projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.92k stars 2.4k forks source link

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

Open AwadYoo opened 2 months ago

AwadYoo commented 2 months ago

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: