Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 341566

Summary: NullPointerException in Open Model Element dialog
Product: [Modeling] TMF Reporter: Mirko Raner <mirko>
Component: XtextAssignee: Jan Koehnlein <jan>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: elbrown, jan, sven.efftinge, tmf.xtext-inbox
Version: 1.0.1Flags: sven.efftinge: indigo+
Target Milestone: M7   
Hardware: All   
OS: All   
Whiteboard:

Description Mirko Raner CLA 2011-03-31 20:19:27 EDT
We're getting an NPE in the Open Model Element dialog when we perform the following steps:

(1) enter some search text in the element name field, and then
(2) remove all text from the element name field, leaving it empty

The error message and stack trace is:

Message: An internal error occurred during: "Calculate result size".

java.lang.NullPointerException
    at org.eclipse.xtext.ui.search.IteratorJob$1.compare(IteratorJob.java:68)
    at org.eclipse.xtext.ui.search.IteratorJob$1.compare(IteratorJob.java:1)
    at java.util.Arrays.mergeSort(Arrays.java:1293)
    at java.util.Arrays.mergeSort(Arrays.java:1282)
    at java.util.Arrays.sort(Arrays.java:1210)
    at java.util.Collections.sort(Collections.java:159)
    at com.google.common.collect.Lists.sortedCopy(Lists.java:214)
    at org.eclipse.xtext.ui.search.IteratorJob.sortedCopy(IteratorJob.java:64)
    at org.eclipse.xtext.ui.search.IteratorJob.run(IteratorJob.java:59)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

We're not sure what exactly is going on here, but it looks like the comparator could use some safety guards in line 68:

    private Collection<IEObjectDescription> sortedCopy(Iterable<IEObjectDescription> list) {
        return Lists.sortedCopy(matches, new Comparator<IEObjectDescription>() {
            public int compare(IEObjectDescription o1, IEObjectDescription o2) {
                int diff = o1.getQualifiedName().compareToIgnoreCase(o2.getQualifiedName());
                if(diff==0) {
                    diff = o1.getEClass().getName().compareToIgnoreCase(o2.getEClass().getName());
                    if(diff==0) {
                        diff = o1.getEObjectURI().toString().compareTo(o2.getEObjectURI().toString());
                    }
                }
                return diff;
            }
        });
    }

There may be a problem with our model in that getName() returns null for some EClasses, but the comparison should probably handle this more gracefully.
Comment 1 Jan Koehnlein CLA 2011-04-08 10:49:48 EDT
Fix pushed to master.

Now you should really fix your Ecore models ! :-)
Comment 2 Karsten Thoms CLA 2017-09-19 17:27:07 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 3 Karsten Thoms CLA 2017-09-19 17:38:21 EDT
Closing all bugs that were set to RESOLVED before Neon.0