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

val within a parameterized (generic) inner class causes a NullPointerException upon compilation #434

Closed
lombokissues opened this issue Jul 14, 2015 · 15 comments
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail javac

Comments

@lombokissues
Copy link

Migrated from Google Code (issue 361)

@lombokissues
Copy link
Author

👤 [email protected]   🕗 Apr 11, 2012 at 21:01 UTC

What steps will reproduce the problem?

  1. Attempt to compile TestVal.java

What is the expected output? What do you see instead?
Expect that the java file compiles properly and the bar variable is inferred to be an Integer. Instead, we get a stack trace with a NullPointerException:

error: Lombok visitor handler class lombok.javac.handlers.HandleVal failed: java.lang.NullPointerException
java.lang.NullPointerException
at com.sun.tools.javac.comp.Check$Validator.visitTypeApply(Check.java:761)
at com.sun.tools.javac.tree.JCTree$JCTypeApply.accept(JCTree.java:1697)
at com.sun.tools.javac.comp.Check.validate(Check.java:732)
...

What version of the product are you using? On what operating system?
Used with 0.10.4, 0.11.2, on MacOSX 10.7.3, with JDK 1.6.0_29.

Please provide any additional information below.

I'm not absolutely sure what the conditions are to produce the error, but when I use the concrete type instead of val, it works. Also, if the inner class does not involve a parameterized class, it seems to be fine, too (i.e. change the class to a Runnable instead of a Comparable).

@lombokissues
Copy link
Author

👤 [email protected]   🕗 Apr 11, 2012 at 21:01 UTC

🔗 TestVal.java View file

@lombokissues
Copy link
Author

👤 [email protected]   🕗 Apr 11, 2012 at 21:03 UTC

I meant 0.11.0, not 0.11.2. Sorry! Also, I used this with the 0.10.4 of the lombok-pg version.

@lombokissues
Copy link
Author

👤 r.spilker   🕗 Apr 11, 2012 at 23:21 UTC

Hypothesis:

When we encounter a 'val', we need to do something calling 'attr'ing the entire block that contains the val statement. This basically assigns types to each expression in it. In order to 'attr', javac needs to have a table with names in them; otherwise it wouldn't know what "new MyOwnClass();" meant.

The problem is this: When annotation processors (and thus, lombok) are called by javac, javac has done the minimum necessary work to make the public API of annotation processors work. This involves creating the aforementioned symbol table (because you can ask for i.e. the method members of a type), but NOT the attr stuff (because that's for statements inside a method, and you can't get to statements with the public annotation API. Lombok actually can, but that's the hacky part of what lombok does). That's why we 'fake' attr by creating a copy of the method or initializer block and then calling attr on that.

The problem is that we made the assumption that javac FULLY fills in the symbol table.

Now we get to the actual hypothesis:

Our hypothesis is that javac only fills in those symbols which it must to support the public annotations API. When you have a local class declaration (these come in 3 variants: An anonymous inner class on a field declaration, an anonymous inner class in a block, and a method local class), then there is NO WAY for a user of the public annotations api to get there, and thus javac decides NOT to create a symbol for the methods in such a class (and possibly not for the class itself either).

This means the method that we end up wanting to 'attr' does not have a symbol. No symbol means 'attr' cannot work.

In practice we could just start the 'attr' process from the deepest node that DOES have a symbol (which would be the field itself), but this doesn't work; maybe we can make that work but I somewhat doubt it. If we dig 'deeper', down to the compareTo method in the TestVal example, we've moved into territory that's invisible with the public annotation API, and therefore there are no symbols here, and therefore we can't attr here.

We don't know of an easy solution to this dilemma. Presumably it'll be one of the following two strategies:

  • Create symbols, possibly first copy the tree and then create symbols for the copy (and then restore the symbol table somehow; these things are cached unfortunately). Then we attr the compareTo method as normal.
  • Figure out how to make the 'attr this copy of the entire field declaration, anonymous inner class declaration and all' work 'better'. Right now it does not attr the generics on the field and the anonymous inner class declaration but it does need them later on, resulting in the NPE.

I have significantly more faith in option 2. Also, option 2 is effectively how it works now, but, when generics are on the anonymous inner class, this will fail. The fail condition should be easy to explain:

ANY use of 'val' ANYWHERE in ANY local class, if the local class has generics, will fail with an NPE.

NB: It is trivial to generate an error on the usage of 'val' with some sort of message saying that, unfortunately, we can't support val inside type parameterized local classes.

@lombokissues lombokissues added accepted The issue/enhancement is valid, sensible, and explained in sufficient detail javac labels Jul 14, 2015
@lombokissues
Copy link
Author

👤 Eric6iese   🕗 Jun 01, 2012 at 14:50 UTC

Hi,

I ran into this issue in my ant build on a regular basis. I love using comparators, functions, predicates and that stuff from time to time... Solving the issue is easy after the second time, but it was real pain in the first build, and it had lessened my trust in the val feature.

It's not that i restrain from using it now - far from it! However, i am concerned that other people who start to use val could get frustrated pretty fast by this, since there is no clue at all in the compiler output where the problem occured, and why.

I would make a suggestion for this one: Is there a way for lombok to find out that it is in a hidden inner class? If so, could it just emit an error and tell the user that val does not work here, much like in traditional for-loops?

That is a step back, but it might help until a real solution to this compiler dilemma is out. And this is really an edge case were I don't care if I can't use val for now.

@lombokissues
Copy link
Author

👤 amanic   🕗 Aug 29, 2012 at 03:14 UTC

I just hit this with 0.11.4
I'm so thankful to have found this bug, it would have taken me forever to figure this out.
Please implement that trivial message to tell poor users what the possible cause is so we have a swimming chance to avoid it.
And also mention it on the val documentation page.

@lombokissues
Copy link
Author

👤 askoning   🕗 Oct 08, 2013 at 10:01 UTC

Issue #578 has been merged into this issue.

@lombokissues
Copy link
Author

End of migration

@artgo
Copy link

artgo commented Mar 19, 2017

Reproduces on Lombok 1.16.14 Oracle javac 1.8.0_112 Apache Maven 3.3.9
Compilation error:

[ERROR] Lombok visitor handler class lombok.javac.handlers.HandleVal failed: java.lang.NullPointerException
Exception while resolving: NODE LOCAL (class com.sun.tools.javac.tree.JCTree$JCVariableDecl) @val()
final ___Lombok_VAL_Attrib__ newAppScreen = AppScreen.builder().pageContent(pageContent).build()
java.lang.NullPointerException
	at com.sun.tools.javac.comp.Check$Validator.visitTypeApply(Check.java:1259)
	at com.sun.tools.javac.tree.JCTree$JCTypeApply.accept(JCTree.java:2135)
	at com.sun.tools.javac.comp.Check$Validator.validateTree(Check.java:1359)
	at com.sun.tools.javac.comp.Check.validate(Check.java:1230)
	at com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1055)
	at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:852)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
	at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:661)
	at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1124)
	at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
	at lombok.javac.JavacResolution.attrib(JavacResolution.java:226)
	at lombok.javac.JavacResolution.memberEnterAndAttribute(JavacResolution.java:199)
	at lombok.javac.JavacResolution.resolveMethodMember(JavacResolution.java:146)
	at lombok.javac.handlers.HandleVal.visitLocal(HandleVal.java:138)
	at lombok.javac.JavacNode.traverse(JavacNode.java:100)
	at lombok.javac.JavacAST.traverseChildren(JavacAST.java:143)
	at lombok.javac.JavacNode.traverse(JavacNode.java:85)
	at lombok.javac.JavacAST.traverseChildren(JavacAST.java:143)
	at lombok.javac.JavacNode.traverse(JavacNode.java:75)
	at lombok.javac.JavacAST.traverseChildren(JavacAST.java:143)
	at lombok.javac.JavacNode.traverse(JavacNode.java:70)
	at lombok.javac.JavacAST.traverse(JavacAST.java:139)
	at lombok.javac.HandlerLibrary.callASTVisitors(HandlerLibrary.java:257)
	at lombok.javac.JavacTransformer.transform(JavacTransformer.java:71)
	at lombok.javac.apt.LombokProcessor.process(LombokProcessor.java:250)
	at lombok.core.AnnotationProcessor$JavacDescriptor.process(AnnotationProcessor.java:114)
	at lombok.core.AnnotationProcessor.process(AnnotationProcessor.java:164)
	at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(AnnotationProcessor.java:59)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
	at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
	at com.sun.tools.javac.main.Main.compile(Main.java:523)
	at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
	at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
	at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:125)
	at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:169)
	at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:825)
	at org.apache.maven.plugin.compiler.TestCompilerMojo.execute(TestCompilerMojo.java:153)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	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)

@BullyWiiPlaza
Copy link

BullyWiiPlaza commented Mar 4, 2019

Can this please be fixed? I'm still getting the exception using IntelliJ IDEA and the Lombok plugin v0.23-EAP on one of my projects:
Error:java: Lombok visitor handler class lombok.javac.handlers.HandleVal failed: java.lang.NullPointerException

I don't know which piece of code causes it. Sometimes it goes through without the exception though which is odd. Why is this error non-deterministic as well?

The maven dependency for Lombok is:

<dependency>
	<groupId>org.projectlombok</groupId>
	<artifactId>lombok</artifactId>
	<version>1.18.6</version>
	<scope>provided</scope>
</dependency>

@nhuanluong
Copy link

Lombok Plugin on IntelliJ has an issue with members has comments /* */. When members have a comment, it cannot build.
example:

/* comment
* The issue of Lombok is here.
*/
DataTable datatable;

@nirujans
Copy link

I am also getting this issue with lombok v1.18.12

@BullyWiiPlaza
Copy link

Update
When building with maven, I actually get more details.

[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ My-Project ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 324 source files to D:\Programs\Source Codes\Java\IntelliJ\My-Project\target\classes
Exception while resolving: NODE LOCAL (class com.sun.tools.javac.tree.JCTree$JCVariableDecl) @val()
final ___Lombok_VAL_Attrib__ iterationLocale = iterationLanguage.getLocale()(RegularFileObject[D:\Programs\Source Codes\Java\IntelliJ\My-Project\src\main\java\com\mycompany\translations\LanguageChooserManager.java])
java.lang.NullPointerException
        at com.sun.tools.javac.comp.Check$Validator.visitSelect(Check.java:1310)
        at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1897)
        at com.sun.tools.javac.comp.Check$Validator.validateTree(Check.java:1359)
        at com.sun.tools.javac.comp.Check.validate(Check.java:1230)
        at com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1055)
        at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:852)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
        at com.sun.tools.javac.comp.Attr.visitForeachLoop(Attr.java:1168)
        at com.sun.tools.javac.tree.JCTree$JCEnhancedForLoop.accept(JCTree.java:1035)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
        at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:661)
        at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1124)
        at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
        at com.sun.tools.javac.comp.Attr.visitTry(Attr.java:1354)
        at com.sun.tools.javac.tree.JCTree$JCTry.accept(JCTree.java:1173)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
        at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:661)
        at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1124)
        at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
        at com.sun.tools.javac.comp.Attr.visitTry(Attr.java:1377)
        at com.sun.tools.javac.tree.JCTree$JCTry.accept(JCTree.java:1173)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
        at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:661)
        at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1124)
        at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
        at com.sun.tools.javac.comp.Attr.visitIf(Attr.java:1584)
        at com.sun.tools.javac.tree.JCTree$JCIf.accept(JCTree.java:1269)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
        at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:661)
        at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1124)
        at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
        at lombok.javac.JavacResolution.attrib(JavacResolution.java:239)
        at lombok.javac.JavacResolution.memberEnterAndAttribute(JavacResolution.java:207)
        at lombok.javac.JavacResolution.resolveMethodMember(JavacResolution.java:155)
        at lombok.javac.handlers.HandleVal.visitLocal(HandleVal.java:145)
        at lombok.javac.JavacNode.traverse(JavacNode.java:120)
        at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
        at lombok.javac.JavacNode.traverse(JavacNode.java:126)
        at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
        at lombok.javac.JavacNode.traverse(JavacNode.java:126)
        at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
        at lombok.javac.JavacNode.traverse(JavacNode.java:126)
        at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
        at lombok.javac.JavacNode.traverse(JavacNode.java:126)
        at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
        at lombok.javac.JavacNode.traverse(JavacNode.java:126)
        at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
        at lombok.javac.JavacNode.traverse(JavacNode.java:126)
        at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
        at lombok.javac.JavacNode.traverse(JavacNode.java:126)
        at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
        at lombok.javac.JavacNode.traverse(JavacNode.java:126)
        at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
        at lombok.javac.JavacNode.traverse(JavacNode.java:126)
        at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
        at lombok.javac.JavacNode.traverse(JavacNode.java:105)
        at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
        at lombok.javac.JavacNode.traverse(JavacNode.java:95)
        at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
        at lombok.javac.JavacNode.traverse(JavacNode.java:90)
        at lombok.javac.JavacAST.traverse(JavacAST.java:218)
        at lombok.javac.HandlerLibrary.callASTVisitors(HandlerLibrary.java:276)
        at lombok.javac.JavacTransformer.transform(JavacTransformer.java:64)
        at lombok.javac.apt.LombokProcessor.process(LombokProcessor.java:326)
        at lombok.core.AnnotationProcessor$JavacDescriptor.process(AnnotationProcessor.java:187)
        at lombok.core.AnnotationProcessor.process(AnnotationProcessor.java:237)
        at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(AnnotationProcessor.java:90)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
        at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
        at com.sun.tools.javac.main.Main.compile(Main.java:523)
        at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
        at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
        at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:126)
        at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:169)
        at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:785)
        at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
        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:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Lombok visitor handler class lombok.javac.handlers.HandleVal failed: java.lang.NullPointerException
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  26.055 s
[INFO] Finished at: 2021-05-24T10:20:40+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project My-Project: Compilation failure
[ERROR] Lombok visitor handler class lombok.javac.handlers.HandleVal failed: java.lang.NullPointerException
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

I'm not even using an inner class. The piece of code is this:

// For caching
private static List<Language> languages;

// ...	

private void initializeResourceBundle()
{
	if (languageSelection != null
			&& languageSelection.getItemCount() > 0)
	{
		val language = languageSelection.getItemAt(languageSelection.getSelectedIndex());
		val locale = language.getLocale();
		setDefaultLocale(locale);
		resourceBundle = getBundle(resourceBundleName, locale);
		populateApplicationLanguages();
	} else
	{
		try
		{
			// Try the current language and country
			resourceBundle = getBundle(resourceBundleName);
		} catch (MissingResourceException exactBundleNotFound)
		{
			try
			{
				val locale = Locale.getDefault();
				val language = locale.getLanguage();

				// Try the same language only
				for (val iterationLanguage : languages) // <-- Changing this to "final Language" instead of val fixes the compilation issue
				{
					val iterationLocale = iterationLanguage.getLocale();
					val iterationLanguageTag = iterationLocale.getLanguage();

					if (iterationLanguageTag.equals(language))
					{
						setDefaultLocale(iterationLocale);
						resourceBundle = getBundle(resourceBundleName);

						return;
					}
				}

				throw new MissingResourceException("", "", "");
			} catch (MissingResourceException languageNotFound)
			{
				// Still error? Switch to the default language then
				resourceBundle = getBundle(resourceBundleName, defaultLocale);
				setDefaultLocale(defaultLocale);
			}
		}
	}

	if (resourceBundle == null)
	{
		// Should never happen, this is just an assertion
		throw new IllegalStateException("Resource bundle expected to be initialized!");
	}
}

Language is another class I defined in a different .java file. Strange.

Dependency:

<dependency>
	<groupId>org.projectlombok</groupId>
	<artifactId>lombok</artifactId>
	<version>1.18.18</version>
	<scope>provided</scope>
</dependency>

@rzwitserloot
Copy link
Collaborator

This may be very hard to fix and not worth fixing, given that instead we'd like to migrate val towards var instead. The 'fix' is then: Upgrade lombok (and be on at least java10).

@Rawi01
Copy link
Collaborator

Rawi01 commented Sep 14, 2021

@rzwitserloot I think I fixed this one in #2840, at least the stacktrace is similar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail javac
Projects
None yet
Development

No branches or pull requests

7 participants