Community
Participate
Working Groups
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()); } });
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.