This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 168226 - [Viewers] default ViewerComparator is case sensitive (doesn't match spec)
Summary: [Viewers] default ViewerComparator is case sensitive (doesn't match spec)
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 4.4 M3   Edit
Assignee: Curtis Windatt CLA
QA Contact: Hitesh CLA
URL:
Whiteboard:
Keywords:
: 384061 (view as bug list)
Depends on: 414172
Blocks:
  Show dependency tree
 
Reported: 2006-12-15 11:12 EST by Boris Bokowski CLA
Modified: 2013-10-01 06:52 EDT (History)
12 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Boris Bokowski CLA 2006-12-15 11:12:23 EST
I'm implementing some kind of viewer and found out that default comparator 
is sorting case SENSITIVE while JavaDoc says it's case INSENSITIVE:

JavaDoc of method int compare(viewer, object, object) form 
ViewerComparator:
  * The default implementation of this method is based on
  * comparing the elements' categories as computed by the <code> category 
</code>
  * framework method. Elements within the same category are further 
  * subjected to a case insensitive compare of their label strings, either
  * as computed by the content viewer's label provider, or their 
  * <code>toString</code> values in other cases. Subclasses may 
override.</p>

but when you'll go deeply to get the source code of the default 
comparator, which you'll find in Policy.java, there will be:

private static Comparator getDefaultComparator(){
return new Comparator(){
/**
* Compares string s1 to string s2.  
* 
* @param s1 string 1
* @param s2 string 2
* @return Returns an integer value. Value is less than zero if source 
is
*         less than target, value is zero if source and target are 
equal,
*         value is greater than zero if source is greater than target.
* @exception ClassCastException the arguments cannot be cast to 
Strings.
*/
public int compare(Object s1, Object s2) {
return ((String)s1).compareTo((String)s2);
}
};
}
Comment 1 Boris Bokowski CLA 2006-12-15 11:13:14 EST
(copied from the newsgroup)
Comment 2 Boris Bokowski CLA 2009-11-26 09:51:19 EST
Hitesh is now responsible for watching bugs in the [Viewers] component area.
Comment 3 Curtis Windatt CLA 2013-08-01 10:25:27 EDT
*** Bug 384061 has been marked as a duplicate of this bug. ***
Comment 4 Curtis Windatt CLA 2013-08-01 10:33:13 EDT
PDE has its own set of comparators to work around this (See ListUtil in PDE or Bug 414172).  If the default behaviour was fixed to follow the javadoc, PDE could remove a lot of this code.

Policy is an internal class, though I see it is used in the java project wizards, the log view and the patch comparator.  Does anyone object to changing the behaviour?
Comment 5 Curtis Windatt CLA 2013-08-01 10:34:35 EDT
To be clear, this means that anyone using the string comparator from Policy would get a case-insensitive search going forward.
Comment 6 Dani Megert CLA 2013-08-02 05:19:35 EDT
(In reply to comment #5)
> To be clear, this means that anyone using the string comparator from Policy
> would get a case-insensitive search going forward.

Sounds too dangerous as it affects existing clients outside Platform UI.
Comment 7 Lars Vogel CLA 2013-08-02 08:02:25 EDT
> Sounds too dangerous as it affects existing clients outside Platform UI.

The fix would correct the implementation which seems currently incorrect. AFAIK the contract is that platform implements according to the Javadoc. Suggested fix: https://git.eclipse.org/r/#/c/15087/
Comment 8 Dani Megert CLA 2013-08-02 08:35:31 EDT
(In reply to comment #7)
> > Sounds too dangerous as it affects existing clients outside Platform UI.
> 
> The fix would correct the implementation which seems currently incorrect.
> AFAIK the contract is that platform implements according to the Javadoc.
> Suggested fix: https://git.eclipse.org/r/#/c/15087/

Well, the Javadoc was wrong and is still wrong (even the good old ViewerSorter has the same issue since day one), especially now, that a policy is used. Even with your fix, most people will get the workbench's comparator, which correctly uses a Collator instance (which is case-sensitive for most locales) as it did since day one where we used the ViewerSorter.

==> Update the Javadoc to say that a policy is used and that the workbench uses a Collator instance and don't touch the getDefaultComparator() which was like that for years.
Comment 9 Curtis Windatt CLA 2013-09-24 16:16:30 EDT
https://git.eclipse.org/r/#/c/16734/
Proposed javadoc update
Comment 10 Paul Webster CLA 2013-09-30 16:04:06 EDT
(In reply to Curtis Windatt from comment #9)
> https://git.eclipse.org/r/#/c/16734/
> Proposed javadoc update

Released spec update: http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=5dbded47a1c2497b55218571ea57ed75454d836f

PW
Comment 11 Dani Megert CLA 2013-10-01 06:52:34 EDT
Verified in master.