Community
Participate
Working Groups
The Environment Variables property page allows duplicates when modifying them from the table view. The method EnvironmentVariablesForm.validateName(String) does not find the duplicates. For lines 594-604, "if (itemName.equals(name) && i != envVarTable.getSelectionIndex())" would work to check for duplicates. The current way looks for two matches when comparing, but it won't find two matches because it is searching through the saved table, and the string that the user is typing is not yet saved. It will find the duplicate environment variable variable if you save a duplicate first.
This sounds like a good suggestion. Would you want to submit a patch for this? We can help you with any questions you have (such as getting the CVS module).
Created attachment 109987 [details] Patch to fix duplicate name checking in the environment variables page I, Justin Lin, declare that I developed attached code from scratch, without referencing any 3rd party materials except material licensed under the EPL. I am authorized by my employer to make this contribution under the EPL.
I must admit that I haven't tried this out, but looking at the source code I cannot understand why your version of the code would find any duplicates that the original version did not find?
envVarTable.getItem(i) gets the items that are committed in the table. So, if you have two items, "var1" and "var2", already in the table, and you change "var2" to "var1" (it's no committed until you press enter), the items returned by envVarTable.getItem(i) will still be "var1" and "var2", so numberFound will be 1, hence it doesn't hit the error block. If you change it to (numberFound >= 1), then it will give an error everytime you commit something and try to modify it, because it will always find itself in the table. So in my patch, it'll look for only one duplicate but makes sure it isn't itself.
Oh, another clarification is that this check is done while the user is typing, not after he presses enter.
Patch applied, thanks. Welcome to our "Hall of Fame": http://www.eclipse.org/dsdp/tm/development/contributors.php I think that the check for duplicates should also be done in case invalidNameChars==null, but for now I decided to apply the patch unchanged.
Created attachment 117661 [details] Patch to check duplicates even if invalidNameChars==null Additional patch committed as well.