Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException when using Java 10 and val #1974

Open
udalrich opened this issue Dec 7, 2018 · 7 comments
Open

NullPointerException when using Java 10 and val #1974

udalrich opened this issue Dec 7, 2018 · 7 comments
Labels
parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these.

Comments

@udalrich
Copy link

udalrich commented Dec 7, 2018

When compiling with the Java 10 compiler, maven and lombok 1.18.4, I get the following stack trace below.

The code being compiled looks like

 package fail;

import lombok.val;
import java.util.List;
import java.util.Set;

public class Fail {
    String getString() { return null; }
    Set getSet() { return null; }
    List getStuff() { return null; }

    public void theTest() {
        String x = getString();
        val x = getSet();

        // Error is on the next line
        val stuff = getStuff();

    }
}

The above code gives an actual error, and I have not been able to get a small test case to reproduce it. This has happened multiple times to me, and it seems to generally involve errors in the expressions being assigned to val and often using one type when a different type is needed.

This is particularly annoying if you have maven fork the compiler, as then the entire stack trace, including the information about where the error is, disappears.

If inspecting the code does not show a problem, I can also install a custom jar with extra logging / debugging information at the problem point.

[INFO] Compiling 7 source files to /Users/me/projects/target/test-classes
Exception while resolving: NODE LOCAL (class com.sun.tools.javac.tree.JCTree$JCVariableDecl) @val()
final _Lombok_VAL_Attrib gatewayMessage = sendLoginRequest()(SimpleFileObject[/Users/me/projects//src/test/java/me/MyTest.java])
java.lang.NullPointerException
at jdk.compiler/com.sun.tools.javac.comp.Check.checkRaw(Check.java:1462)
at jdk.compiler/com.sun.tools.javac.comp.Check$Validator.validateTree(Check.java:1445)
at jdk.compiler/com.sun.tools.javac.comp.Check.validate(Check.java:1314)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1152)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:956)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:722)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:741)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1274)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1020)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:722)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4722)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4613)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4542)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitClassDef(Attr.java:949)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:722)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitAnonymousClassDefinition(Attr.java:2395)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitNewClass(Attr.java:2287)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1689)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:700)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitExec(Attr.java:1771)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1452)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:722)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:741)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1292)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1020)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:722)
at lombok.javac.JavacResolution.attrib(JavacResolution.java:235)
at lombok.javac.JavacResolution.memberEnterAndAttribute(JavacResolution.java:203)
at lombok.javac.JavacResolution.resolveMethodMember(JavacResolution.java:151)
at lombok.javac.handlers.HandleVal.visitLocal(HandleVal.java:143)
at lombok.javac.JavacNode.traverse(JavacNode.java:120)
at lombok.javac.JavacAST.traverseChildren(JavacAST.java:125)
at lombok.javac.JavacNode.traverse(JavacNode.java:110)
at lombok.javac.JavacAST.traverseChildren(JavacAST.java:125)
at lombok.javac.JavacNode.traverse(JavacNode.java:95)
at lombok.javac.JavacAST.traverseChildren(JavacAST.java:125)
at lombok.javac.JavacNode.traverse(JavacNode.java:126)
at lombok.javac.JavacAST.traverseChildren(JavacAST.java:125)
at lombok.javac.JavacNode.traverse(JavacNode.java:126)
at lombok.javac.JavacAST.traverseChildren(JavacAST.java:125)
at lombok.javac.JavacNode.traverse(JavacNode.java:105)
at lombok.javac.JavacAST.traverseChildren(JavacAST.java:125)
at lombok.javac.JavacNode.traverse(JavacNode.java:95)
at lombok.javac.JavacAST.traverseChildren(JavacAST.java:125)
at lombok.javac.JavacNode.traverse(JavacNode.java:90)
at lombok.javac.JavacAST.traverse(JavacAST.java:121)
at lombok.javac.HandlerLibrary.callASTVisitors(HandlerLibrary.java:276)
at lombok.javac.JavacTransformer.transform(JavacTransformer.java:79)
at lombok.javac.apt.LombokProcessor.process(LombokProcessor.java:321)
at lombok.core.AnnotationProcessor$JavacDescriptor.process(AnnotationProcessor.java:151)
at lombok.core.AnnotationProcessor.process(AnnotationProcessor.java:201)
at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(AnnotationProcessor.java:99)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:964)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:881)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.access$2100(JavacProcessingEnvironment.java:110)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1202)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1311)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1250)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:928)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:100)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:142)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:96)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:90)
at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:126)
at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:174)
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1129)
at org.apache.maven.plugin.compiler.TestCompilerMojo.execute(TestCompilerMojo.java:181)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:194)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Lombok visitor handler class lombok.javac.handlers.HandleVal failed: java.lang.NullPointerException
[INFO] 1 error

@rspilker
Copy link
Collaborator

Could it be that it's the raw types?

@rspilker rspilker added the parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these. label Dec 17, 2018
@udalrich
Copy link
Author

udalrich commented Jan 2, 2019

I have also seen this with non-generic types (String, MyClass) I think I have seen it with generic types that are properly constrained (Set, List<? extends Number>)

@RaviH
Copy link

RaviH commented Apr 30, 2019

I am getting this issue with Java 11 and val from Lombok.

@rspilker
Copy link
Collaborator

Another suggestion: Does this only happen when compiling test code? We've had some other reports about bugs that could only be reproduced when compiling tests.

@JarvisCraft
Copy link

Having the same issue when using val randomly in different places of the exact class (sometimes it is NPE, sometimes StackOverflow). Above is a PR with this error and attempts to fix it (Travis shows full error-logs there).

@JarvisCraft
Copy link

Looks like it happens (in some of these cases) due to the following javac code:

@Override
public void visitTypeApply(JCTypeApply tree) {
    if (tree.type.hasTag(CLASS)) { // <-- here
        // .......
    }
}

@ignaciolarranaga
Copy link

ignaciolarranaga commented Apr 4, 2020

I'm having this issue with openjdk 12/lombok 1.18.12
And it is random also, pretty annoying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these.
Projects
None yet
Development

No branches or pull requests

5 participants