Bug 288174

Summary: [search] NullPointerException when searching for type references
Product: [Eclipse Project] JDT Reporter: Peter Hendriks <phendriks>
Component: CoreAssignee: Frederic Fusier <frederic_fusier>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: Olivier_Thomann, satyam.kandula, srikanth_sankaran
Version: 3.5   
Target Milestone: 3.6 M4   
Hardware: PC   
OS: Windows Vista   
Whiteboard:
Attachments:
Description Flags
Proposed patch
none
Jar file for the added test none

Description Peter Hendriks CLA 2009-08-31 15:31:47 EDT
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)
Build Identifier: M20090807-0800

When searching for Java type references there appears to be a bug in the Search which causes a NullPointerException on some code. The following stack trace is in the log:

java.lang.NullPointerException
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.newTypeReferenceMatch(MatchLocator.java:1519)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.newTypeReferenceMatch(MatchLocator.java:1528)
	at org.eclipse.jdt.internal.core.search.matching.TypeReferenceLocator.matchReportReference(TypeReferenceLocator.java:327)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2648)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2133)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2612)
	at org.eclipse.jdt.internal.core.search.matching.MemberDeclarationVisitor.visit(MemberDeclarationVisitor.java:258)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1282)
	at org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression.traverse(QualifiedAllocationExpression.java:483)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.traverse(MessageSend.java:554)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:237)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2111)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2612)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2339)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:1627)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1037)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1078)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1195)
	at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:223)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:507)
	at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:551)
	at org.eclipse.jdt.internal.ui.search.JavaSearchQuery.run(JavaSearchQuery.java:144)
	at org.eclipse.search2.internal.ui.InternalSearchUI$InternalSearchJob.run(InternalSearchUI.java:91)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)


Reproducible: Always

Steps to Reproduce:
An easy way to reproduce:

1. Create a new Java project and attach a Sun JDK 1.6.0_14 Java runtime library with a proper source attachment (you can check this by trying to navigate into java.lang.String using the tree in the package explorer).
2. Start a new Java Search, type "*" as a search string to search for everything, and select Search for: "Type" and Limit to: "References".
3. Search in JRE Libraries only, workspace scope, and start searching.

After a few seconds, the error above occurs.



When the match locations do not include "annotations", "type parameter bounds", "wildcard bounds" and "type arguments" but does include everything else, the Java JDK can be scanned succesfully for type references (about 400,000 references).
Comment 1 Frederic Fusier CLA 2009-11-30 06:51:48 EST
The MatchLocator does protect itself when the createHandle(...) method returns null in certain circumstances but not always. Typically it does not when the type references is found in the type arguments generic method, but it does when the reference is found in the method body and this method fails to find the handler of a method in an anonymous type...

I'll fix the NPE in this case, but the Search Engine will still fails to report type references inside binary type anonymous (see bug 151389)...
Comment 2 Frederic Fusier CLA 2009-12-01 05:38:50 EST
Created attachment 153434 [details]
Proposed patch

This was finally not the same origin than bug 151389. In this case, the problem came from the fact that similar matches were not used while creating the method handle...
Comment 3 Frederic Fusier CLA 2009-12-01 05:41:46 EST
Created attachment 153437 [details]
Jar file for the added test

This jar file needs to be put in workspace/JavaSearchBugs/lib folder of the org.eclipse.jdt.core.tests.model project in order to pass the added test JavaSearchBugTests.testBug288174()...
Comment 4 Frederic Fusier CLA 2009-12-01 05:43:22 EST
Released for 3.6M4 in HEAD stream.
Comment 5 Satyam Kandula CLA 2009-12-08 06:18:53 EST
Verified for 3.6M4 using Build id: I20091207-1800