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] @Slf4j causes error with variable named org but not with org1 #3738

Open
AwadYoo opened this issue Sep 4, 2024 · 0 comments
Open

[BUG] @Slf4j causes error with variable named org but not with org1 #3738

AwadYoo opened this issue Sep 4, 2024 · 0 comments

Comments

@AwadYoo
Copy link

AwadYoo commented Sep 4, 2024

Description:

Problem Description:

When using the @Slf4j annotation in a class, defining an instance variable named org triggers an error: Cannot reference a non-static variable org from a static context, even though the org variable is not being referenced in a static context like the main method. However, if the variable is renamed to org1, the code works fine without any errors.

Steps to Reproduce:

  1. Create a simple Java class and annotate it with @Slf4j.
  2. Define an instance variable named org.
  3. Observe the error message without attempting to reference org in a static context.

Example Code:

@Slf4j
public class AppConfig {
    private String org;

    public static void main(String[] args) {
        System.out.println(123); // org is not referenced here
    }
}

This code throws the following error:

Cannot reference a non-static variable org from a static context
  1. Rename the variable from org to org1 and run the code again.

Modified Code:

@Slf4j
public class AppConfig {
    private String org1;

    public static void main(String[] args) {
        System.out.println(123); // no issue with org1
    }
}

This code does not produce any errors.

Expected Behavior:

Both org and org1 variables should behave the same way, meaning no errors should occur unless org or org1 is actually being referenced in a static context like the main method.

Actual Behavior:

The compiler throws an error when using org as the variable name, but no error occurs when the variable is named org1.

Environment Information:

  • Lombok Version: 1.18.22
  • JDK Version: 1.8.0_281
  • Operating System: Windows 10 Professional, Version 22H2 (Build 19045.4842)
  • IDE Version: IntelliJ IDEA 2024.1 (Ultimate Edition), Build #IU-241.14494.240, Runtime version: 17.0.10+8-b1207.12 amd64
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

1 participant