Bug 369512 - NPE in MessageSend.analyseCode() while running builder 'Java Builder'
Summary: NPE in MessageSend.analyseCode() while running builder 'Java Builder'
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: PC Windows 7
: P3 major with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: needinfo
: 404994 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-01-24 08:21 EST by Deepak Azad CLA
Modified: 2023-09-06 12:16 EDT (History)
7 users (show)

See Also:


Attachments
compiler preferences (2.52 KB, application/octet-stream)
2012-01-24 08:21 EST, Deepak Azad CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Deepak Azad CLA 2012-01-24 08:21:18 EST
Created attachment 209964 [details]
compiler preferences

Errors running builder 'Java Builder' on project 'org.eclipse.jdt.compiler.apt'.


java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.analyseCode(MessageSend.java:66)
	at org.eclipse.jdt.internal.compiler.ast.Block.analyseCode(Block.java:37)
	at org.eclipse.jdt.internal.compiler.ast.IfStatement.analyseCode(IfStatement.java:102)
	at org.eclipse.jdt.internal.compiler.ast.Block.analyseCode(Block.java:37)
	at org.eclipse.jdt.internal.compiler.ast.TryStatement.analyseCode(TryStatement.java:156)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.analyseCode(MethodDeclaration.java:109)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.internalAnalyseCode(TypeDeclaration.java:722)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.analyseCode(TypeDeclaration.java:251)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.analyseCode(CompilationUnitDeclaration.java:111)
	at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:759)
	at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:137)
	at java.lang.Thread.run(Thread.java:736)
Comment 1 Ayushman Jain CLA 2012-01-24 08:55:34 EST
Which build? I20120122-2000?
Comment 2 Deepak Azad CLA 2012-01-24 08:59:29 EST
I have 4.2 I20120123-1210 which would use an earlier 3.8 build. o.e.jdt.core version is - org.eclipse.jdt.core_3.8.1.v20120122-0307
Comment 3 Ayushman Jain CLA 2012-01-24 09:08:41 EST
I cannot reproduce using o.e.jdt.compiler.apt , compiled using org.eclipse.jdt.core_3.8.1.v20120122-0307 and attached prefs.
Comment 4 Ayushman Jain CLA 2012-01-24 09:14:03 EST
The line of code on which there's an NPE hasn't changed recently. Deepak could reproduce with a lot of other projects imported in the workspace and a few of them closed. Some weird combination results in this NPE.
So not an urgent issue for M5.

Will investigate if and when a reproducible case becomes available.
Comment 5 Stephan Herrmann CLA 2012-01-24 11:10:25 EST
If line 66 really is the first line of analyseCode where the only deref is this.binding.isStatic() then I'd assume there should be *something* in the logs from the time when resolving this MessageSend failed? Deepak, anything?
Or any compile errors at that time?
Comment 6 Wojciech Rogala CLA 2012-01-31 08:16:12 EST
I got the same situation during build:

!ENTRY org.eclipse.core.resources 4 2 2012-01-31 14:00:47.661
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".
!STACK 0
java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.analyseCode(MessageSend.java:61)
	at org.eclipse.jdt.internal.compiler.ast.Block.analyseCode(Block.java:36)
	at org.eclipse.jdt.internal.compiler.ast.ForeachStatement.analyseCode(ForeachStatement.java:103)
	at org.eclipse.jdt.internal.compiler.ast.Block.analyseCode(Block.java:36)
	at org.eclipse.jdt.internal.compiler.ast.IfStatement.analyseCode(IfStatement.java:99)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.analyseCode(MethodDeclaration.java:104)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.internalAnalyseCode(TypeDeclaration.java:696)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.analyseCode(TypeDeclaration.java:254)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.analyseCode(CompilationUnitDeclaration.java:111)
	at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:769)
	at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:137)
	at java.lang.Thread.run(Thread.java:680)

!ENTRY org.eclipse.core.resources 4 75 2012-01-31 14:00:55.931
!MESSAGE Errors occurred during the build.
!SUBENTRY 1 org.eclipse.jdt.core 4 75 2012-01-31 14:00:55.932
!MESSAGE Errors running builder 'Java Builder' on project 'XXXXXX.EJB'.
!STACK 0
java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.analyseCode(MessageSend.java:61)
	at org.eclipse.jdt.internal.compiler.ast.Block.analyseCode(Block.java:36)
	at org.eclipse.jdt.internal.compiler.ast.ForeachStatement.analyseCode(ForeachStatement.java:103)
	at org.eclipse.jdt.internal.compiler.ast.Block.analyseCode(Block.java:36)
	at org.eclipse.jdt.internal.compiler.ast.IfStatement.analyseCode(IfStatement.java:99)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.analyseCode(MethodDeclaration.java:104)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.internalAnalyseCode(TypeDeclaration.java:696)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.analyseCode(TypeDeclaration.java:254)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.analyseCode(CompilationUnitDeclaration.java:111)
	at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:769)
	at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:137)
	at java.lang.Thread.run(Thread.java:680)


Eclipse:
Version: Indigo Service Release 1
Build id: 20110916-0149

Operatin system:
MacOs Lion

I observed that it does not occur always. When I close all projects, reopen, refresh, clean and build everything is fine but when I refresh and rebuild next time I get this exception.

I changed last time structure of projects too a little more complex.

Unfortunately I can not say how to reproduce this easily.
Comment 7 Wojciech Rogala CLA 2012-01-31 08:41:43 EST
I tried on Eclipse Helios:
Version: Helios Service Release 2
Build id: 20110218-0911

and I still the same problem:

!ENTRY org.eclipse.core.resources 4 75 2012-01-31 14:37:40.232
!MESSAGE Errors occurred during the build.
!SUBENTRY 1 org.eclipse.jdt.core 4 75 2012-01-31 14:37:40.232
!MESSAGE Errors running builder 'Java Builder' on project 'XXXXXXXX.EJB'.
!STACK 0
java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.analyseCode(MessageSend.java:59)
	at org.eclipse.jdt.internal.compiler.ast.Block.analyseCode(Block.java:36)
	at org.eclipse.jdt.internal.compiler.ast.ForeachStatement.analyseCode(ForeachStatement.java:103)
	at org.eclipse.jdt.internal.compiler.ast.Block.analyseCode(Block.java:36)
	at org.eclipse.jdt.internal.compiler.ast.IfStatement.analyseCode(IfStatement.java:95)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.analyseCode(MethodDeclaration.java:89)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.internalAnalyseCode(TypeDeclaration.java:695)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.analyseCode(TypeDeclaration.java:253)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.analyseCode(CompilationUnitDeclaration.java:111)
	at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:765)
	at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:137)
	at java.lang.Thread.run(Thread.java:680)
Comment 8 Ayushman Jain CLA 2012-01-31 09:15:58 EST
(In reply to comment #6)
> I got the same situation during build:
Hi, can you answer comment 5 ? It'll be good to have the exact test case which triggers this NPE to really fix this problem. Thanks!
If you can, please attach your project too.
Comment 9 Wojciech Rogala CLA 2012-01-31 09:31:08 EST
Unfortunately I can not attach my projects. Only message which I receive in workspaceNew/.metadata/.log I copied to comment 6. Afterwards I see in eclipse "Problems" tab at first place:
"Internal compiler error: java.lang.NullPointerException" and on next places that some types from another connected project are missing but this is probably because of NPE
Comment 10 Wojciech Rogala CLA 2012-01-31 12:04:24 EST
my problem I solved by change in eclipse "preferences"->"Build order" to manual one
project with model I just moved above another project with model which is used by first one
Comment 11 Ayushman Jain CLA 2012-02-01 00:09:36 EST
(In reply to comment #10)
> my problem I solved by change in eclipse "preferences"->"Build order" to manual
> one project with model I just moved above another project with model which is >used by first one

Thanks for the investigation. I still want to find out why the binding obtained is null, because just adding a null check may hide a bigger bug.
Comment 12 Ayushman Jain CLA 2012-02-01 00:16:55 EST
Investigating further in MessageSend.resolveType(...), I can see that there's a possibility of obtaining a null binding via org.eclipse.jdt.internal.compiler.lookup.Scope.findMethod(ReferenceBinding, char[], TypeBinding[], InvocationSite, boolean) if one of its arguments cannot be resolved. SO, adding a null check might  actually be the correct fix here.
Comment 13 Ayushman Jain CLA 2012-02-01 00:27:11 EST
Srikanth, can we be more resilient than just returning null from findMethod(..)? It seems to have been introduced by bug 69471.
Comment 14 Stephan Herrmann CLA 2012-02-02 06:22:13 EST
(In reply to comment #13)
> Srikanth, can we be more resilient than just returning null from
> findMethod(..)? It seems to have been introduced by bug 69471.

My 2c: I like the idea to avoid null, most clients seem to be unaffected by such change, with *possibly* one exception: have you checked getImplicitMethod() for different behavior with null vs. ProblemMethodBinding? Given that you see a difference, it *is* probably exactly in getImplicitMethod(), right? Do you have a test case for the difference?
Comment 15 Stephan Herrmann CLA 2012-02-02 06:23:58 EST
(In reply to comment #14)
> Given that you see a difference, it *is* probably exactly in
> getImplicitMethod(), right?

Delete that part, I didn't look at the obvious direct impact in MessageSend.
Comment 16 Dani Megert CLA 2013-04-05 08:20:27 EDT
*** Bug 404994 has been marked as a duplicate of this bug. ***
Comment 17 Dani Megert CLA 2013-04-05 08:30:21 EDT
Got this too.

!ENTRY org.eclipse.core.resources 4 2 2013-04-05 13:31:11.469
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".
!STACK 0
java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.analyseCode(MessageSend.java:83)
	at org.eclipse.jdt.internal.compiler.ast.Block.analyseCode(Block.java:42)
	at org.eclipse.jdt.internal.compiler.ast.ForeachStatement.analyseCode(ForeachStatement.java:125)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.analyseCode(MethodDeclaration.java:113)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.internalAnalyseCode(TypeDeclaration.java:732)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.analyseCode(TypeDeclaration.java:257)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.analyseCode(CompilationUnitDeclaration.java:111)
	at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:776)
	at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:137)
	at java.lang.Thread.run(Thread.java:722)
Comment 18 Stephan Herrmann CLA 2013-04-05 15:46:39 EDT
(In reply to comment #17)
> Got this too.

You don't by any chance have a reproducing example?
Comment 19 Dani Megert CLA 2013-04-08 05:17:38 EDT
(In reply to comment #18)
> (In reply to comment #17)
> > Got this too.
> 
> You don't by any chance have a reproducing example?

No, if so, I would have provided them :-(.
Comment 20 Tomas Gradin CLA 2014-07-03 07:08:15 EDT
This is still present in Eclipse 4.4 (build 20140612-0600).

I'll try to create a reproducing example.
Comment 21 Rafael Chaves CLA 2019-09-25 13:30:01 EDT
No test case, but I think I was changing the default JRE environment for the workspace when it happened. Note that there are other bugs reported for similar issues, at least one allegedly fixed.

This is the stacktrace generated in 4.11 (buildId=4.11.0.I20190307-0500)

java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.analyseCode(MessageSend.java:146)
	at org.eclipse.jdt.internal.compiler.ast.ReturnStatement.analyseCode(ReturnStatement.java:90)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.analyseCode(MethodDeclaration.java:128)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.internalAnalyseCode(TypeDeclaration.java:772)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.analyseCode(TypeDeclaration.java:271)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.analyseCode(CompilationUnitDeclaration.java:130)
	at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:898)
	at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:145)
	at java.lang.Thread.run(Thread.java:748)
Comment 22 Stephan Herrmann CLA 2019-09-25 16:21:21 EDT
we will happily work on this once we have an example.
Comment 23 Eclipse Genie CLA 2021-09-15 01:07:10 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 24 Eclipse Genie CLA 2023-09-06 12:16:50 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.