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] @Log fails on nested enums #2990

Closed
charphi opened this issue Oct 8, 2021 · 4 comments · Fixed by #3113
Closed

[BUG] @Log fails on nested enums #2990

charphi opened this issue Oct 8, 2021 · 4 comments · Fixed by #3113
Assignees
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail bug
Milestone

Comments

@charphi
Copy link
Contributor

charphi commented Oct 8, 2021

Describe the bug
Compilation fails when the annotation @log is set on a nested enum.

To Reproduce
Here is an example:

class Example {

  @Log
  enum Status  { OK, KO }
}

The following error appears during compilation:
@Log is not supported on non-static nested classes.

Expected behavior
Should compile without error.
Was working fine in 1.18.20

Version info (please complete the following information):

  • Lombok 1.18.22
  • all platforms

Additional context
Addind the keyword static to the enum seems to workaround the problem.

@rzwitserloot
Copy link
Collaborator

Context for implementers: Lombok demands static on inner classes here because lombok wants to make a static field, and in java that isn't legal (or wasn't for most of its lifetime) in non-static inners. Apparently the idea is that such static fields should be placed in the outer class instead. However, enums are by definition static - they do not hold a reference to an instance of the enclosing class. You can put private static final fields in them and you've always been able to do that. Thus, lombok should just shut up and do it, its overly zealous here. It should consider enum type defs as inherently static.

@rzwitserloot rzwitserloot added this to the next-version milestone Oct 8, 2021
@rzwitserloot rzwitserloot self-assigned this Oct 8, 2021
@rzwitserloot rzwitserloot added accepted The issue/enhancement is valid, sensible, and explained in sufficient detail bug labels Oct 8, 2021
@varkart
Copy link
Contributor

varkart commented Feb 13, 2022

@rzwitserloot if this hasn't been worked on already, I would love to contribute.

@rzwitserloot
Copy link
Collaborator

@varkart Feel free! Should be as simple as removing two lines, or at least 'guarding' an existing if (mods.static) { addTheError(); return; } with checking if the type is NOT an enum first. Make sure to add your name to AUTHORS as well :) – no need to mess with the docs, we'll review and take care of that part.

varkart added a commit to varkart/lombok that referenced this issue Feb 17, 2022
varkart added a commit to varkart/lombok that referenced this issue Feb 17, 2022
varkart added a commit to varkart/lombok that referenced this issue Feb 17, 2022
varkart added a commit to varkart/lombok that referenced this issue Feb 17, 2022
varkart added a commit to varkart/lombok that referenced this issue Feb 17, 2022
varkart added a commit to varkart/lombok that referenced this issue Feb 17, 2022
@varkart
Copy link
Contributor

varkart commented Feb 17, 2022

@rzwitserloot at your convenience could you plz review the PR and let me know if any additional changes are needed.

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 bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants