Bug 244051 - JJ: Environment Variables property page allows duplicates in table
Summary: JJ: Environment Variables property page allows duplicates in table
Status: RESOLVED FIXED
Alias: None
Product: Target Management
Classification: Tools
Component: RSE (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P5 trivial (vote)
Target Milestone: 3.1 M3   Edit
Assignee: Martin Oberhuber CLA
QA Contact: Martin Oberhuber CLA
URL:
Whiteboard:
Keywords: bugday, helpwanted
Depends on:
Blocks:
 
Reported: 2008-08-13 14:11 EDT by Justin Lin CLA
Modified: 2008-11-12 09:07 EST (History)
2 users (show)

See Also:


Attachments
Patch to fix duplicate name checking in the environment variables page (1.82 KB, patch)
2008-08-14 10:20 EDT, Justin Lin CLA
mober.at+eclipse: iplog+
Details | Diff
Patch to check duplicates even if invalidNameChars==null (13.62 KB, patch)
2008-11-12 09:07 EST, Martin Oberhuber CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Justin Lin CLA 2008-08-13 14:11:27 EDT
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.
Comment 1 Martin Oberhuber CLA 2008-08-13 14:17:20 EDT
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).
Comment 2 Justin Lin CLA 2008-08-14 10:20:28 EDT
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.
Comment 3 Martin Oberhuber CLA 2008-08-14 10:27:59 EDT
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?
Comment 4 Justin Lin CLA 2008-08-14 10:58:01 EDT
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.
Comment 5 Justin Lin CLA 2008-08-14 11:01:31 EDT
Oh, another clarification is that this check is done while the user is typing, not after he presses enter.
Comment 6 Martin Oberhuber CLA 2008-11-12 09:03:40 EST
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.
Comment 7 Martin Oberhuber CLA 2008-11-12 09:07:42 EST
Created attachment 117661 [details]
Patch to check duplicates even if invalidNameChars==null

Additional patch committed as well.