Bug 224458

Summary: [search] NPE trying to search for a field declaration
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Frederic Fusier <frederic_fusier>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: philippe_mulet, pwebster
Version: 3.4   
Target Milestone: 3.4 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed patch none

Description Olivier Thomann CLA 2008-03-27 16:12:25 EDT
Using eclipse.buildId=I20080327-0100
java.version=1.6.0_05
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=fr_CA
Framework arguments:  D:\eclipse\sdk\eclipse\org.eclipse.platform -showlocation
Command-line arguments:  -os win32 -ws win32 -arch x86 D:\eclipse\sdk\eclipse\org.eclipse.platform -consolelog -console -showlocation

I got this failure by doing Ctrl + Shift + G on a field reference.

java.lang.NullPointerException
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.createHandle(MatchLocator.java:574)
at org.eclipse.jdt.internal.core.search.matching.MemberDeclarationVisitor.storeHandle(MemberDeclarationVisitor.java:138)
at org.eclipse.jdt.internal.core.search.matching.MemberDeclarationVisitor.visit(MemberDeclarationVisitor.java:229)
at org.eclipse.jdt.internal.compiler.ast.SingleNameReference.traverse(SingleNameReference.java:901)
at org.eclipse.jdt.internal.compiler.ast.ConditionalExpression.traverse(ConditionalExpression.java:502)
at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.traverse(LocalDeclaration.java:245)
at org.eclipse.jdt.internal.compiler.ast.SwitchStatement.traverse(SwitchStatement.java:380)
at org.eclipse.jdt.internal.compiler.ast.Block.traverse(Block.java:127)
at org.eclipse.jdt.internal.compiler.ast.TryStatement.traverse(TryStatement.java:853)
at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:239)
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:2583)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2312)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:1604)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1036)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1077)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1209)
at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:217)
at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:500)
at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:550)
at org.eclipse.jdt.internal.ui.search.JavaSearchQuery.run(JavaSearchQuery.java:143)
at org.eclipse.search2.internal.ui.InternalSearchUI$InternalSearchJob.run(InternalSearchUI.java:94)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Comment 1 Olivier Thomann CLA 2008-03-27 16:20:10 EDT
I am investigating with my workspace since I cannot extract a simple test case.
Comment 2 Olivier Thomann CLA 2008-03-27 16:32:41 EDT
I could not reproduce on the next restart. So since I was not running in self-hosting, I have no way to find out what was wrong.
Comment 3 Olivier Thomann CLA 2008-03-27 16:55:39 EDT
Set back to normal as I cannot reproduce anymore once I restarted my workspace.
However there is a potential NPE in the calls on that line.
Comment 4 Frederic Fusier CLA 2008-03-28 11:41:27 EDT
*** Bug 224645 has been marked as a duplicate of this bug. ***
Comment 5 Frederic Fusier CLA 2008-03-28 11:45:12 EDT
Paul,
Did you have compiler errors in your workspace?
Did search stop to work after this NPE?
Can you reproduce it easily?
Comment 6 Frederic Fusier CLA 2008-03-28 11:48:38 EDT
Although I cannot reproduce while searching  for references to System.err in an Eclipse full-source workspace, I think it could be good to make the code safe and check if the resolved type is null in MatchLocator.createHandle(AbstractVariableDeclaration, IJavaElement) method...
Comment 7 Frederic Fusier CLA 2008-03-28 12:26:12 EDT
Created attachment 93998 [details]
Proposed patch
Comment 8 Paul Webster CLA 2008-03-28 12:39:36 EDT
(In reply to comment #5)
> Paul,
> Did you have compiler errors in your workspace?

No, the workspace just has a lot of warnings.  Specifically, I have platform-ui, platform-ui-examples and platform-ui-tests checked out from HEAD, with ui.carbon and ui.win32 closed.

> Did search stop to work after this NPE?

Yes, it stopped the search.

> Can you reproduce it easily?

I restarted my workbench and was able to reproduce it using the same System.err steps.

PW


Comment 9 Frederic Fusier CLA 2008-03-28 14:11:10 EDT
Olivier helped me to reproduce the problem and hopefully we can verified that the patch really fixes the problem. However, depending on further investigations, I might open a new bug for M7 to tune the fix if I can precisely understand why this binding is null in this case. Then the fix would be on the origin of the problem instead of its symptom only...

Released for 3.4M6 in HEAD stream.
Comment 10 Olivier Thomann CLA 2008-03-28 14:40:03 EDT
Paul problem is identical. The resolveType is null, because the match is inside a binary method with source attached, but the method's statements are not resolved.
So a null check will fix this problem, but I am not convinced that we should get that far in this case.
The method's statement should be resolved or we should not try to locate a match inside the method.
Comment 11 Paul Webster CLA 2008-03-28 14:47:47 EDT
And just before I forget, my NPE was while searching:

local declaration:
boolean succeed = new Main(new PrintWriter(new OutputStreamWriter(out)), new PrintWriter(new OutputStreamWriter(err)), true, null, null).compile(arguments);


class: public class org.eclipse.jdt.internal.compiler.tool.EclipseCompiler
method: public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) {


PW
Comment 12 Frederic Fusier CLA 2008-03-29 07:22:02 EDT
Verified for 3.4M6 using I20080328-1410.