Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 443252

Summary: [1.8][compiler] NullPointerException in ReferenceExpression.shouldGenerateImplicitLambda when compiling in version 4.4
Product: [Eclipse Project] JDT Reporter: Jonathan Rochette <jrochette>
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: VERIFIED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, kaj.hejer, srikanth_sankaran, steinbach.tim
Version: 4.4   
Target Milestone: 4.5 M3   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Jonathan Rochette CLA 2014-09-03 15:43:24 EDT
Build id: 20140612-0600

Compiling in version 4.4.0 of the product crash with a NPE. It was working fine with version 4.3.2

Here is the stacktrace I see in the logs :

java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.ast.ReferenceExpression.shouldGenerateImplicitLambda(ReferenceExpression.java:185)
	at org.eclipse.jdt.internal.compiler.ast.ReferenceExpression.generateCode(ReferenceExpression.java:193)
	at org.eclipse.jdt.internal.compiler.ast.Statement.generateArguments(Statement.java:287)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.generateCode(MessageSend.java:425)
	at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.generateCode(LocalDeclaration.java:151)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:325)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:270)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:566)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:635)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.generateCode(CompilationUnitDeclaration.java:368)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1210)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:689)
	at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1183)
	at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:809)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider$1.run(ASTProvider.java:544)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.createAST(ASTProvider.java:537)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.getAST(ASTProvider.java:480)
	at org.eclipse.jdt.ui.SharedASTProvider.getAST_aroundBody0(SharedASTProvider.java:128)
	at org.eclipse.jdt.ui.SharedASTProvider$AjcClosure1.run(SharedASTProvider.java:1)
	at scala.tools.eclipse.contribution.weaving.jdt.cfprovider.ClassFileProviderAspect.ajc$around$scala_tools_eclipse_contribution_weaving_jdt_cfprovider_ClassFileProviderAspect$7$67c4e2a5proceed(ClassFileProviderAspect.aj:1)
	at scala.tools.eclipse.contribution.weaving.jdt.cfprovider.ClassFileProviderAspect.ajc$around$scala_tools_eclipse_contribution_weaving_jdt_cfprovider_ClassFileProviderAspect$7$67c4e2a5(ClassFileProviderAspect.aj:224)
	at org.eclipse.jdt.ui.SharedASTProvider.getAST(SharedASTProvider.java:128)
	at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:170)
	at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$3.run(SelectionListenerWithASTManager.java:155)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Comment 1 Srikanth Sankaran CLA 2014-09-03 19:47:43 EDT
Are you able to attach a test case that shows the problem ? TIA.
Comment 2 Srikanth Sankaran CLA 2014-09-09 22:12:52 EDT
Jonathan, any luck with reproducing in a small test case ?
Comment 3 Jonathan Rochette CLA 2014-09-10 08:42:52 EDT
I have been trying to make a small test case to reproduce my issue, but all my attemps were unsuccessful. I will try a new approach later this week.
Comment 4 Srikanth Sankaran CLA 2014-09-17 14:28:02 EDT
(In reply to Jonathan Rochette from comment #3)
> I have been trying to make a small test case to reproduce my issue, but all
> my attemps were unsuccessful. I will try a new approach later this week.

To the extent you are able to share code, even a big test case is fine, I can
reduce it down. Thanks.
Comment 5 Tim Steinbach CLA 2014-09-22 11:45:26 EDT
I have just encountered the same issue and was able to reproduce it.
See this gist: (I am having trouble attaching the file directly)
https://gist.github.com/NeQuissimus/1986029efa51e5b18111

The issue is a method reference or a lambda inside a constructor call, it seems.
Separating the two calls does not cause the error to be thrown.
Comment 6 Srikanth Sankaran CLA 2014-09-22 13:45:17 EDT
(In reply to Tim Steinbach from comment #5)
> I have just encountered the same issue and was able to reproduce it.
> See this gist: (I am having trouble attaching the file directly)
> https://gist.github.com/NeQuissimus/1986029efa51e5b18111
> 
> The issue is a method reference or a lambda inside a constructor call, it
> seems.
> Separating the two calls does not cause the error to be thrown.

Do you mind opening a different ticket ? The call stack is completely different
and so is unrelated to the present problem. 

Also you can simply copy + paste the code inline into as part of defect 
submission - no need to attach. To add the code to the test suite, we need
it to be posted on bugzilla. TIA.
Comment 7 Tim Steinbach CLA 2014-09-22 14:30:52 EDT
My bad, the stack traces looked similar.
I did create a separate issue.
Comment 8 Srikanth Sankaran CLA 2014-09-22 22:47:56 EDT
Same as bug 444772

*** This bug has been marked as a duplicate of bug 444772 ***
Comment 9 Jay Arthanareeswaran CLA 2014-10-29 00:29:25 EDT
Verified for 4.5 M3 using I20141028-2000 build
Comment 11 Kaj Hejer CLA 2015-06-12 13:53:58 EDT
Please ignore my previous comment. Sorry!
Comment 12 Kaj Hejer CLA 2015-06-12 15:46:57 EDT
Hi, it is me again. Sorry for the noise! I redrew my comment because I thought I couldn't reproduce this issue, but I can.

If I replace the line

return jdbcTemplate.query(sql, this::customComponentMapper);

with

return null;

I don't get this ajdt error.

Please see my previous comment for sourcecode and info about eclipse, ajdt and java versions.
Comment 13 Kaj Hejer CLA 2015-06-12 15:55:21 EDT
It seems that a workaround is to replace 

   return jdbcTemplate.query(sql, this::customComponentMapper);

with

   RowMapper<CustomComponent> rowMapper = this::customComponentMapper;
   return jdbcTemplate.query(sql, rowMapper);

Then I can't reproduce this issue.
Comment 14 Jay Arthanareeswaran CLA 2015-06-30 02:48:25 EDT
(In reply to Kaj Hejer from comment #10)
> Hi
> 
> I see this problem on line 135 in the following file:
> https://utv.uio.no/stash/projects/WAPP/repos/foransatte/commits/
> b2707460eb9cf7bb6516c849a819900d7d216489#src/main/java/no/uio/webapps/
> foransatte/jdbc/CustomComponentDAOImpl.java
> 
> See stracktrace and versioninfo on
> https://dev.eclipse.org/recommenders/community/confess/#/incidents/
> yxeTVTAgmSpbZGIb4sP7bYSXbnjrZeg56HhzsBaQHR3fK16wOoeHdUJnoezSptD1

Can you extract this into a small snippet? I have trouble setting up the project when doing a "mvn install".