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

@UtilityClass should produce a compiler error, when put on a non-static inner class #3778

Open
tomsit-ionos opened this issue Nov 9, 2024 · 3 comments
Assignees
Labels
parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these.

Comments

@tomsit-ionos
Copy link

tomsit-ionos commented Nov 9, 2024

TLDR

When adding @UtilityClass on a non-static inner class with Java 21, then this causes VM crashes and other non-obvious problems.

If u add the static modifier, it works (for me).

See my stripped down reproduction repo @ https://github.com/tomsit-ionos/lombok-utilclass-bug

Also notice that the intellij decompiler is not able to open generated class-file and i verified this also with an online decompiler.

Long story

For me it was a nested class inside a record.

It took me a good day to figure out what's going on b/c i ran into this while upgrade a keycloak extension from KC 25 -> 26.
This set me on the wrong mental path and i was guessing there were some wired upgrade problems at play.

To add to the fun:
The nested class didnt pose a problem for non-testcontainer junit tests using that inner class, ie. these were green!
But only with the intellij junit runner -- which is what I typically use, while working on code, due to the better DX.

What i failed to notice was, that theses normal tests failed when executed by mvn test (e.g. on CI) with this message:

...
[ERROR] The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
...

Originally posted by @tomsit-ionos in #3679 (comment)

@Rawi01 Rawi01 self-assigned this Nov 23, 2024
@Rawi01
Copy link
Collaborator

Rawi01 commented Nov 23, 2024

Interesting, I decompiled the generated class file and the output is different between javac 17 and 21. This difference is also present at the bytecode level.

   ...
   public static final class InnerClass {
      public static final String BAR = "bar";
-     // $FF: synthetic field
-     final OuterClass this$0;

      @Generated
      private InnerClass(OuterClass var1) {
-        this.this$0 = var1;
         throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
      }
   }

@Rawi01
Copy link
Collaborator

Rawi01 commented Nov 23, 2024

TIL: javac does no longer add references to unused outer classes for targets >= Java 18. So this does not cause the problem.

@Rawi01
Copy link
Collaborator

Rawi01 commented Nov 24, 2024

I cannot build a class file that is broken, can you reproduce it on another system? Can you also please share the Java version you are using for your build?

@Rawi01 Rawi01 added the parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these. label Nov 24, 2024
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

2 participants