Bug 62426 - NPE in Java SearchEngine (3.0M8)
Summary: NPE in Java SearchEngine (3.0M8)
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 M9   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-16 17:31 EDT by Frank Sauer CLA
Modified: 2004-05-17 09:42 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frank Sauer CLA 2004-05-16 17:31:01 EDT
This NPE occurs when an anonymous type is found as the search result. The 
PatternLocator class fails to create a match in:

protected void matchReportReference(ASTNode reference, IJavaElement element, 
int accuracy, MatchLocator locator) throws CoreException {
	SearchMatch match = locator.newReferenceMatch(referenceType(), element, 
accuracy, reference.sourceStart, reference.sourceEnd+1);
	locator.report(match);
}

The reference and element parameters look good to me as far as I can tell:

reference is shown as:

 {
  public int compare(Object o1, Object o2) {
    AbstractMetricSource left = (AbstractMetricSource) o1;
    AbstractMetricSource right = (AbstractMetricSource) o2;
    Metric lm = left.getValue(id);
    Metric rm = right.getValue(id);
    int result;
    if ((lm == null))
        {
          result = ((rm == null) ? 0 : (- 1));
        }
    else
        {
          result = (- lm.compareTo(rm));
        }
    if ((result != 0))
        return result;
    return left.getHandle().compareTo(right.getHandle());
  }
}

and element is shown as:

printValues(List, String, XMLPrintStream, MetricDescriptor) (not open) [in 
MetricsFirstExporter [in MetricsFirstExporter.java [in 
net.sourceforge.metrics.internal.xml [in src [in net.sourceforge.metrics]]]]]

which is the surrounding method of the anonymous inner class.


match being null results in an NPE in MatchLocator:

SearchEngine$ResultCollectorAdapter.acceptSearchMatch(SearchMatch) line: 59
MatchLocator.report(SearchMatch) line: 1033
TypeDeclarationLocator(PatternLocator).matchReportReference(ASTNode, 
IJavaElement, int, MatchLocator) line: 230
MatchLocator.reportMatching(AbstractMethodDeclaration, IJavaElement, int, 
boolean, MatchingNodeSet) line: 1214
MatchLocator.reportMatching(TypeDeclaration, IJavaElement, int, 
MatchingNodeSet, int) line: 1422
MatchLocator.reportMatching(CompilationUnitDeclaration, boolean) line: 1279
MatchLocator.process(PossibleMatch, boolean) line: 968
MatchLocator.locateMatches(JavaProject, PossibleMatch[], int, int) line: 622
MatchLocator.locateMatches(JavaProject, PossibleMatchSet) line: 656
MatchLocator.locateMatches(SearchDocument[]) line: 747
JavaSearchParticipant.locateMatches(SearchDocument[], SearchPattern, 
IJavaSearchScope, SearchRequestor, IProgressMonitor) line: 157
QualifiedTypeDeclarationPattern(InternalSearchPattern).findMatches
(SearchParticipant[], IJavaSearchScope, SearchRequestor, IProgressMonitor) 
line: 107
SearchEngine.search(SearchPattern, SearchParticipant[], IJavaSearchScope, 
SearchRequestor, IProgressMonitor) line: 739


The anonymous inner class being reported as the search result looks like this:

		Collections.sort(values, new Comparator() {

			public int compare(Object o1, Object o2) {
				AbstractMetricSource left = 
(AbstractMetricSource)o1;
				AbstractMetricSource right = 
(AbstractMetricSource)o2;
				Metric lm = left.getValue(id);
				Metric rm = right.getValue(id);
				int result;
			    if (lm == null) { // BUG #826997 
			        result = (rm == null) ? 0 : -1;
			    } else {
			        result = -lm.compareTo(rm); // BUG 746394
			    }
				if (result != 0) return result;
				return left.getHandle().compareTo
(right.getHandle());
			}
			
		});
Comment 1 Jerome Lanneluc CLA 2004-05-17 09:42:13 EDT
PatternLocator#matchReportReference(...) has changed since 3.0 M8 to always 
succeed in creating a search match.Moreover it filters out null search matches 
(in case one would add a new reference match without updating this method).

Please reopen if you see this problem in a recent integration build.