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] Inner class not made static by @UtilityClass #3176

Closed
TysonMN opened this issue Apr 15, 2022 · 2 comments
Closed

[BUG] Inner class not made static by @UtilityClass #3176

TysonMN opened this issue Apr 15, 2022 · 2 comments

Comments

@TysonMN
Copy link

TysonMN commented Apr 15, 2022

Describe the bug
The documentation of @UtilityClass says it makes all inner classes static, but that doesn't seem to be the case.

Steps to Reproduce
Compile this code:

import lombok.experimental.UtilityClass;

@UtilityClass
public class MyOuterClass {
    public void method() {
        new MyInnerClass().method();
    }

    private class MyInnerClass {
        public void method() { }
    }
}

Expected behavior
The code compiles.

Actual behavior
The code does not compile. Instead, I get this compile error:

MyOuterClass.java:8: error: non-static variable this cannot be referenced from a static context
new MyInnerClass().method();
^

Workaround
The code compiles after explicitly adding static to the inner class as shown in the following code:

import lombok.experimental.UtilityClass;

@UtilityClass
public class MyOuterClass {
    public void method() {
        new MyInnerClass().method();
    }

    private static class MyInnerClass {
        public void method() { }
    }
}

Additional context
Here is a screenshot showing where the documentation of @UtilityClass says

All methods, inner classes, and fields in the class are marked static.

Screen Shot 2022-04-15 at 10 34 00 AM

Version info

  • Lombok version: Not sure. IntelliJ bundles Lombok and says version it is using is bundled 213.7172.25.

Screen Shot 2022-04-15 at 10 52 52 AM

  • javac version: 11.0.12
  • Platform: I am using IntelliJ. Here is the info obtained from IntelliJ IDEA -> About IntelliJ IDEA -> Copy:

IntelliJ IDEA 2021.3.3 (Community Edition)
Build #IC-213.7172.25, built on March 15, 2022
Runtime version: 11.0.14.1+1-b1751.46 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 12.3.1
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 16
Registry:
debugger.watches.in.variables=false

Non-Bundled Plugins:
org.antlr.intellij.plugin (1.17)
idea.plugin.protoeditor (213.6461.28)
org.jetbrains.kotlin (213-1.6.10-release-961-IJ6777.52)
PythonCore (213.7172.26)
CheckStyle-IDEA (5.62.0)
org.intellij.scala (2021.3.20)

Kotlin: 213-1.6.10-release-961-IJ6777.52

@rzwitserloot
Copy link
Collaborator

This sounds familiar, as in, already fixed. However, its possible the lombok plugin didn't. It is a separate codebase; the issue should probably be filed on their tracker. It's here.

@TysonMN
Copy link
Author

TysonMN commented Apr 19, 2022

This sounds familiar, as in, already fixed.

Ah, yes. This issue is a duplicate of #3097.

However, its possible the lombok plugin didn't. It is a separate codebase; the issue should probably be filed on their tracker. It's here.

Thanks for the pointer. I will follow up there.

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

No branches or pull requests

2 participants