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

[BUG] @Delegate misbehaves in anonymous classes #3240

Open
DQKrait opened this issue Aug 4, 2022 · 1 comment · May be fixed by #3336
Open

[BUG] @Delegate misbehaves in anonymous classes #3240

DQKrait opened this issue Aug 4, 2022 · 1 comment · May be fixed by #3336

Comments

@DQKrait
Copy link

DQKrait commented Aug 4, 2022

Describe the bug
@Delegate on a field within an anonymous class returned by a method won't compile if that method has parameters.
This started happening in the newer Lombok versions, at least since 1.18.22.

To Reproduce
Consider this example:

public class DelegateTest {
    Foo getFooOverride(String param) {
        return new Foo() {
            @Delegate final FooOverride override = new FooOverride();
        };
    }

    static class Foo {
    }

    static class FooOverride {
    }
}

This doesn't compile with newer lombok versions. If we remove String param – it works.

Compilation error:

java.lang.NullPointerException
	at lombok.javac.handlers.HandleDelegate.handle(HandleDelegate.java:182)
	at lombok.javac.HandlerLibrary$AnnotationHandlerContainer.handle(HandlerLibrary.java:113)
	at lombok.javac.HandlerLibrary.handleAnnotation(HandlerLibrary.java:256)
	at lombok.javac.JavacTransformer$AnnotationVisitor.visitAnnotationOnField(JavacTransformer.java:84)
	at lombok.javac.JavacNode.traverse(JavacNode.java:135)
	at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
	at lombok.javac.JavacNode.traverse(JavacNode.java:100)
	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: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.JavacTransformer.transform(JavacTransformer.java:63)
	at lombok.javac.apt.LombokProcessor.process(LombokProcessor.java:328)
	at lombok.core.AnnotationProcessor$JavacDescriptor.process(AnnotationProcessor.java:187)
	at lombok.core.AnnotationProcessor.process(AnnotationProcessor.java:241)
	at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(AnnotationProcessor.java:90)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:985)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:901)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1227)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1340)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1258)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:936)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:147)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
	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:1134)
	at org.apache.maven.plugin.compiler.TestCompilerMojo.execute(TestCompilerMojo.java:180)
	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 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:566)
	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)

Expected behavior
@Delegate annotation in anonymous classes should work regardless of how their outer methods are defined.

Version info
Reproduces with Lombok v1.18.22 and higher. Works fine with lombok 1.18.12.
Javac: 11.0.13, also reproduces with newer versions.

@DQKrait
Copy link
Author

DQKrait commented Aug 4, 2022

A clearer error message produced with javac 17.0.4:

java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Symbol$ClassSymbol.getEnclosedElements()" because "lombok.javac.JavacNode.get().sym" is null
	at lombok.javac.handlers.HandleDelegate.handle(HandleDelegate.java:182)
	at lombok.javac.HandlerLibrary$AnnotationHandlerContainer.handle(HandlerLibrary.java:113)
	at lombok.javac.HandlerLibrary.handleAnnotation(HandlerLibrary.java:256)
	at lombok.javac.JavacTransformer$AnnotationVisitor.visitAnnotationOnField(JavacTransformer.java:84)
	at lombok.javac.JavacNode.traverse(JavacNode.java:135)
	at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
	at lombok.javac.JavacNode.traverse(JavacNode.java:100)
	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: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.JavacTransformer.transform(JavacTransformer.java:63)
	at lombok.javac.apt.LombokProcessor.process(LombokProcessor.java:328)
	at lombok.core.AnnotationProcessor$JavacDescriptor.process(AnnotationProcessor.java:187)
	at lombok.core.AnnotationProcessor.process(AnnotationProcessor.java:241)
	at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(AnnotationProcessor.java:90)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:1023)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:939)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1267)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1382)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1234)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:916)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
	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:1134)
	at org.apache.maven.plugin.compiler.TestCompilerMojo.execute(TestCompilerMojo.java:180)
	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 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	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)

Rawi01 added a commit to Rawi01/lombok that referenced this issue Jan 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant