illegal reference to static field from initializer

I found an issue with build for one my projects, this project was working fine on my IDE (eclipse). When i used build tool i encountered this error.

[echo] Compiling the source files .....
    [javac] Compiling 54 source files to /comp/acserver/slaves/node/workspace/build/HelloWorld/build

    [javac] /comp/acserver/slaves/node/workspace/src/com/pkg/config/Person1.java:32: illegal reference to static field from initializer
    [javac]         logger=Logger.getLogger(CustomLogs.getLogName(Person1.class));
    [javac]                                                               
    [javac] /comp/acserver/slaves/node/workspace/src/com/pkg/config/SomeClass.java:28: illegal reference to static field from initializer
    [javac]         logger=Logger.getLogger(CustomLogs.getLogName(SomeClass.class));
    [javac]                                                                    
    [javac] /comp/acserver/slaves/node/workspace/src/com/pkg/config/ContextLookup.java:36: illegal reference to static field from initializer
    [javac]         logger=Logger.getLogger(CustomLogs.getLogName(ContextLookup.class));
    [javac]                                                                      
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 3 errors

  
I tried to find the issue and found that Person1, SomeClass and ContextLookup are not regular java classes but are enumerations. This made me thought, might be static references to external classes from enums are not allowed because of compilation sequence.

public enum ContextLookup
{
.......
Logger logger = null;
........
private ContextLookup()
  {
    this.logger = Logger.getLogger(CustomLogs.getLogName(ContextLookup.class));
    createContext();
    this.props = getPropertiesFromDB();
  }
.............
}

This reason looked little strange as IDE's don't show any error and local compilers also let pass this build.

With some more research i found that on build environment, java compiler from IBM was used. I changed the compiler to Sun java, and everything was back to normal.

Comments

Popular posts from this blog

Caused by: java.sql.SQLTimeoutException: ORA-01013: user requested cancel of current operation

HashiCorp Vault Integration with Ansible Etower using approle

utility to extract date from text with java