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:
Create a simple Java class and annotate it with @Slf4j.
Define an instance variable named org.
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
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
Description:
Problem Description:
When using the
@Slf4j
annotation in a class, defining an instance variable namedorg
triggers an error:Cannot reference a non-static variable org from a static context
, even though theorg
variable is not being referenced in a static context like themain
method. However, if the variable is renamed toorg1
, the code works fine without any errors.Steps to Reproduce:
@Slf4j
.org
.org
in a static context.Example Code:
This code throws the following error:
org
toorg1
and run the code again.Modified Code:
This code does not produce any errors.
Expected Behavior:
Both
org
andorg1
variables should behave the same way, meaning no errors should occur unlessorg
ororg1
is actually being referenced in a static context like themain
method.Actual Behavior:
The compiler throws an error when using
org
as the variable name, but no error occurs when the variable is namedorg1
.Environment Information: