Bug 567784 - [compiler] NPE in Java compiler when using Lombok and jOOL together
Summary: [compiler] NPE in Java compiler when using Lombok and jOOL together
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.17   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-10 12:00 EDT by Petr Bodnar CLA
Modified: 2022-12-24 18:55 EST (History)
0 users

See Also:


Attachments
An example pom.xml for a quick testing project setup (1.05 KB, text/xml)
2020-10-10 12:04 EDT, Petr Bodnar CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Bodnar CLA 2020-10-10 12:00:21 EDT
This is yet another NullPointerException thrown from the Eclipse's Java compiler:

-----
eclipse.buildId=4.17.0.I20200902-1800
java.version=11.0.8
java.vendor=AdoptOpenJDK
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=cs_CZ
Framework arguments:  -product org.eclipse.epp.package.jee.product -product org.eclipse.epp.package.jee.product
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product -data d:\workspace\eclipse-compiler-npe -product org.eclipse.epp.package.jee.product

...

org.eclipse.jdt.core.manipulation
Error
Sat Oct 10 17:09:11 CEST 2020
Error in JDT Core during AST creation

java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.ast.ASTNode.checkInvocationArgument(ASTNode.java:363)
	at org.eclipse.jdt.internal.compiler.ast.ASTNode.checkInvocationArguments(ASTNode.java:449)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:953)
	at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:409)
	at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:270)
	at org.eclipse.jdt.internal.compiler.ast.Block.resolve(Block.java:131)
	at org.eclipse.jdt.internal.compiler.ast.LambdaExpression.resolveType(LambdaExpression.java:458)
	at org.eclipse.jdt.internal.compiler.ast.LambdaExpression.cachedResolvedCopy(LambdaExpression.java:975)
	at org.eclipse.jdt.internal.compiler.ast.LambdaExpression.resolveExpressionExpecting(LambdaExpression.java:1005)
	at org.eclipse.jdt.internal.compiler.lookup.InferenceContext18.addConstraintsToC_OneExpr(InferenceContext18.java:681)
	at org.eclipse.jdt.internal.compiler.lookup.InferenceContext18.addConstraintsToC(InferenceContext18.java:649)
	at org.eclipse.jdt.internal.compiler.lookup.InferenceContext18.inferInvocationType(InferenceContext18.java:433)
	at org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding.computeCompatibleMethod18(ParameterizedGenericMethodBinding.java:271)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.isCompatibleWith(MessageSend.java:1100)
	at org.eclipse.jdt.internal.compiler.lookup.PolyTypeBinding.isCompatibleWith(PolyTypeBinding.java:43)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.parameterCompatibilityLevel(Scope.java:5068)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.parameterCompatibilityLevel(Scope.java:5032)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.computeCompatibleMethod(Scope.java:871)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.computeCompatibleMethod(Scope.java:798)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.findMethod0(Scope.java:1756)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.findMethod(Scope.java:1657)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getMethod(Scope.java:3046)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.findMethodBinding(MessageSend.java:1017)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:838)
	at org.eclipse.jdt.internal.compiler.ast.Expression.resolve(Expression.java:1082)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:664)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:361)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:573)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1490)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1615)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:662)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1243)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:714)
	at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1205)
	at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:820)
	at org.eclipse.jdt.core.manipulation.CoreASTProvider$1.run(CoreASTProvider.java:272)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.jdt.core.manipulation.CoreASTProvider.createAST(CoreASTProvider.java:264)
	at org.eclipse.jdt.core.manipulation.CoreASTProvider.getAST(CoreASTProvider.java:197)
	at org.eclipse.jdt.core.manipulation.SharedASTProviderCore.getAST(SharedASTProviderCore.java:138)
	at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:167)
	at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$1.run(SelectionListenerWithASTManager.java:152)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
-----

This error happens when having a Java code like in the following highly artificial MRE (the problematic line is marked with "// BUG"; in real life, result of calling `Unchecked.consumer()` would be typically passed to a `forEach` method of a stream):

    package snippet;
    
    import org.jooq.lambda.Unchecked;
    
    import lombok.val;
    
    public class Snippet {
        public static void main(String[] args) {
            Unchecked.consumer(item -> {
                val res = transform(item.toString());// BUG
            });
        }
    
        protected static String transform(Object obj) {
            return "test: " + obj;
        }
    }

Here are my findings so far:

* The error happens when combining Lombok's `val` and jOOL's `Unchecked.consumer()` as shown above.
* It doesn't matter if target Java version is 8 or 11.
* There are various ways of how to avoid the error:
    * use `var` or `final var` instead of `val` since Java 10
    * call `Unchecked.<TypeName>consumer()` instead of `Unchecked.consumer()`
    * don't pass the variable to a method - do inline evaluation of the same stuff
    * don't call any method on the variable when passing it to a method - so just `transform(item)` in this case

Details:

* Reproduced also with Eclipse 4.16, i. e. 2020-06.
* Lombok version: 1.18.12 (the latest 1.18.14 introduces another bug in Eclipse `java.lang.NoClassDefFoundError: lombok/launch/PatchFixesHider$Transform` -> for another issue)
* jOOL version: 0.9.14
* A real life example: [DefaultCasConfigurationPropertiesSourceLocator.java](https://raw.githubusercontent.com/apereo/cas/v6.2.2/core/cas-server-core-configuration-api/src/main/java/org/apereo/cas/configuration/DefaultCasConfigurationPropertiesSourceLocator.java) from CAS project (probably one of the reasons why they don't support Eclipse for building from source).
Comment 1 Petr Bodnar CLA 2020-10-10 12:04:44 EDT
Created attachment 284418 [details]
An example pom.xml for a quick testing project setup
Comment 2 Petr Bodnar CLA 2020-10-10 14:41:01 EDT
If it helps, I have obtained another error that is probably caused by the same root reason:

-----
java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getMethod(Scope.java:3028)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.findMethodBinding(MessageSend.java:1017)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:838)
	at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:409)
	at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:270)
	at org.eclipse.jdt.internal.compiler.ast.Block.resolve(Block.java:131)
	at org.eclipse.jdt.internal.compiler.ast.LambdaExpression.resolveType(LambdaExpression.java:458)
	at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolvePolyExpressionArguments(ASTNode.java:718)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.findMethodBinding(MessageSend.java:1024)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:838)
	at org.eclipse.jdt.internal.compiler.ast.Expression.resolve(Expression.java:1082)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:664)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:361)
	at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:573)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1490)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1615)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:662)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1243)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:714)
	at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1205)
	at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:820)
	...
-----

This is thrown when `Unchecked.function()` is used within this code: [ReturnEncryptedAttributeReleasePolicy.java](https://github.com/apereo/cas/blob/v6.2.2/core/cas-server-core-authentication-attributes/src/main/java/org/apereo/cas/services/ReturnEncryptedAttributeReleasePolicy.java). And again, changing `val` to `var` helps to solve the problem...
Comment 3 Eclipse Genie CLA 2022-12-24 18:55:55 EST
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.