This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 174776 - [refresh] new filter name is not validated against existing names
Summary: [refresh] new filter name is not validated against existing names
Status: RESOLVED FIXED
Alias: None
Product: Target Management
Classification: Tools
Component: RSE (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 2.0   Edit
Assignee: David McKnight CLA
QA Contact: Martin Oberhuber CLA
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2007-02-20 09:38 EST by Martin Oberhuber CLA
Modified: 2011-05-25 10:24 EDT (History)
1 user (show)

See Also:
ddykstal.eclipse: review+
dmcknigh: review+


Attachments
Vector existing lists passed to ValidatorUniqueString are now sorted to be in sync with passing String array existing lists. (1.10 KB, patch)
2007-05-24 10:45 EDT, Kevin Doyle CLA
mober.at+eclipse: iplog+
Details | Diff
sort Collection arguments so they can be binary searched (3.26 KB, patch)
2007-05-30 18:28 EDT, David Dykstal CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Oberhuber CLA 2007-02-20 09:38:09 EST
Start RSE on fresh, clean workspace.
Create a new dstore-windows connection to localhost with daemon in Team profile.
No filters are created (see bug 142712).
Select file subsystem, right-click > New > Filter
  - filter path = "."
  - filter name = "My Home"
  - filter profile = "Team"
Press Next, Finish.
The filter is shown twice.

This may be related to bug 160394.

-----------Enter bugs above this line-----------
TM 2.0M5 Testing
installation : eclipse-SDK-3.3M5 (I20070209-1006), cdt-4.0M5, emf-2.3M5
RSE install  : RSE-SDK I20070219-1645 + discovery + efs
java.runtime : Sun 1.4.2_13
os.name:     : Windows XP 5.1, Service Pack 1
------------------------------------------------
systemtype   : Unix-ssh / Linux-dstore-processes
targetos     : Red Hat Enterprise Linux WS release 4 (Nahant Update 3)
targetuname  : Linux parser.takefive.co.at 2.6.9-34.EL #1 Fri Feb 24 16:44:51 EST 2006 i686 athlon i386 GNU/Linux
targetvm     : Sun Java HotSpot(TM) Client VM (build 1.4.2_13-b06, mixed mode)
------------------------------------------------
Comment 1 Martin Oberhuber CLA 2007-02-22 07:26:20 EST
Seen the issue again on Linux. After it was possible to create several filters ok without duplicates, suddenly one was shown twice. This was in the private profile, local file subsystem. After refreshing, the filter was shown once only.

Changed the summary accordingly (old value was:)
first created filter shown twice on dstore-windows connection in Team profile

The reason for this issue might be concurrency issue with multiple refresh jobs at the same time. See bug 160394 for a previous similar issue.

Comment 2 David McKnight CLA 2007-03-21 11:56:12 EDT
I tried reproducing this today but it seemed okay.  Is this still something you see?
Comment 3 Martin Oberhuber CLA 2007-05-21 15:45:07 EDT
Haven't seen this for a while now but haven't tried creating a lot of filters either.
Comment 4 Kevin Doyle CLA 2007-05-22 09:52:58 EDT
I haven't seen duplicated filters when creating filters normally, but I just tried this and it messed stuff up.

Create a new workspace.
Create a new filter and give it the name "My Home".  It won't say filter name is in use and will let you continue.
You will have 2 Drives filters, but they will both point to the same thing.  Double clicking on one will open the other.

Same thing happens with Drives if you do it before creating any other filter.  if you create a new filter first then try to create one with the name Drives it won't let you.
Comment 5 Kevin Doyle CLA 2007-05-24 10:45:22 EDT
Created attachment 68582 [details]
Vector existing lists passed to ValidatorUniqueString are now sorted to be in sync with passing String array existing lists.

This patch fixes the issue of being able to create filters with a name that is previously used.

I changed ValidatorUniqueString.setExistingNamesList(Vector) to call the init function which sorts the list.  This needed to be done because Arrays.binarySearch requires a sorted list and the vector provided was not sorted.  It was just in the order that you see in the RSE where My Home is always before Drives.

Legal Message: I, Kevin Doyle, 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, IBM Canada Ltd. to make this
contribution under the EPL.
Comment 6 David Dykstal CLA 2007-05-30 12:00:05 EDT
The patch itself looks fine, but there is another problem in that we are reordering the user passed array in the init method of ValidatorUniqueString. This is not good practice and can have very unintended consequences. It should be fixed as well. Basically a copy of the passed array needs to be made up front in the method.

Note that the validators have all been updated to take Collection arguments instead of Vectors - be sure to resynch prior to fixing.
Comment 7 David McKnight CLA 2007-05-30 12:09:27 EDT
Kevin are there any updates you can make in response to Dave Dykstal's comments?
Comment 8 Martin Oberhuber CLA 2007-05-30 12:23:11 EDT
Setting target milestone RC2 since we have an approved patch.
Comment 9 Kevin Doyle CLA 2007-05-30 13:16:25 EDT
The array that is sorted is a copy of the original array.

		   String newList[] = new String[existingList.length];
		   for (int idx=0; idx<existingList.length; idx++)
		   {
		   	  String string = existingList[idx];
		   	  boolean quoted = (string.indexOf(QUOTE) != -1);
		   	  if (!quoted)
		        newList[idx] = string.toLowerCase();
		      else
		        newList[idx] = quotedToLowerCase(string);
		   }
		   existingList = newList;
		}
		Arrays.sort(existingList);

This needs to be done because for determining if a name is in use we use binarySearch and if the array isn't sorted it's not going to work.
Comment 10 David Dykstal CLA 2007-05-30 18:24:56 EDT
(In reply to comment #9)
> The array that is sorted is a copy of the original array.
> 
>                    String newList[] = new String[existingList.length];
>                    for (int idx=0; idx<existingList.length; idx++)
>                    {
>                           String string = existingList[idx];
>                           boolean quoted = (string.indexOf(QUOTE) != -1);
>                           if (!quoted)
>                         newList[idx] = string.toLowerCase();
>                       else
>                         newList[idx] = quotedToLowerCase(string);
>                    }
>                    existingList = newList;
>                 }
>                 Arrays.sort(existingList);
> 
> This needs to be done because for determining if a name is in use we use
> binarySearch and if the array isn't sorted it's not going to work.
> 

A copy of the array is made only if the comparison is supposed to be case insensitive, otherwise it sorts the orginal array. It should make a copy regardless and sort that. I'll attached a patch that incorporates your change and the changes to init.

Dave M - you'll need to review and commit. Don't forget to update the tm-log.csv file.
Comment 11 David Dykstal CLA 2007-05-30 18:28:20 EDT
Created attachment 69414 [details]
sort Collection arguments so they can be binary searched

Also rewrote the init method to create a copy of the input array prior to sorting.
Comment 12 David McKnight CLA 2007-05-30 20:29:36 EDT
The patch looks good to me.  I guess I need to log Kevin's original contribution when I apply the patch.
Comment 13 David McKnight CLA 2007-05-30 20:37:03 EDT
I've applied the patch.
Comment 14 Kevin Doyle CLA 2007-05-31 09:28:14 EDT
Right if you pass in a String array it doesn't create a copy of the array unless it's not case sensitive, but if you pass in a Collection you convert it into a String array, and then we now make a copy of it again in init.  Shouldn't we just make a copy in the setExistingNames(String[]), so that we aren't doing unnecessary copies?
Comment 15 Martin Oberhuber CLA 2007-05-31 09:33:48 EDT
Copying arrays is less expensive than one might think, so I'd like to just keep this as it is for now given that we've got more important things to do.
Comment 16 Martin Oberhuber CLA 2007-07-19 05:26:59 EDT
When checking for bug #197101, I noticed that this bug has actually been turned into tracking a different issue, so I renamed the SUmmary (old value was: [refresh] new filter is shown twice until refreshed)
Comment 17 Martin Oberhuber CLA 2008-08-13 13:20:13 EDT
[target cleanup] 2.0 RC2 was the original target milestone for this bug
Comment 18 Martin Oberhuber CLA 2011-05-25 10:24:10 EDT
Comment on attachment 68582 [details]
Vector existing lists passed to ValidatorUniqueString are now sorted to be in sync with passing String array existing lists.

Patch ended up being used.