java - Javac fails to compile annotations on static nested classes that have a public enum -


i encountered following javac compilation failure javac did not recognize annotations on static nested class had public enum. once moved enum out of static nested class compilation errors resolved. know why javac failed? java compiler bug? or there java nuance unaware of?

below standalone test case.

fails compile:

package test;  import test.annotationbug.nestedclasswithenum.participanttype;  import lombok.data; import lombok.noargsconstructor;  import com.googlecode.objectify.annotation.embed;  public class annotationbug {    participanttype type;    @embed   @data   @noargsconstructor   public static final class nestedclassnoenum {   }    @embed   @data   @noargsconstructor   public static final class nestedclasswithenum {     participanttype type;      public enum participanttype {       organizer,       registered,       wait_listed     }   } } 

compilation output:

$ javac -classpath /home/avaliani/projects/jars/objectify-4.0b2.jar:/home/avaliani/projects/jars/lombok.jar  test/annotationbug.java test/annotationbug.java:20: error: cannot find symbol   @embed    ^   symbol:   class embed   location: class annotationbug test/annotationbug.java:21: error: cannot find symbol   @data    ^   symbol:   class data   location: class annotationbug test/annotationbug.java:22: error: cannot find symbol   @noargsconstructor    ^   symbol:   class noargsconstructor   location: class annotationbug 

compiles:

package test;  // import test.annotationbug.nestedclasswithenum.participanttype;  import lombok.data; import lombok.noargsconstructor;  import com.googlecode.objectify.annotation.embed;  public class annotationbug {    participanttype type;    @embed   @data   @noargsconstructor   public static final class nestedclassnoenum {   }    @embed   @data   @noargsconstructor   public static final class nestedclasswithenum {     participanttype type;    }    public enum participanttype {     organizer,     registered,     wait_listed   } } 

compiles without errors:

$ javac -classpath /home/avaliani/projects/jars/objectify-4.0b2.jar:/home/avaliani/projects/jars/lombok.jar  test/annotationbug.java 

things point out:

1) note line number of compilation failure. there no problem parsing nestedclassnoenum's annotation.

2) java version:

$ java -version java version "1.7.0_21" openjdk runtime environment (icedtea 2.3.9) (7u21-2.3.9-0ubuntu0.12.10.1) openjdk 64-bit server vm (build 23.7-b01, mixed mode) 

if remove import of static class, code compiles fine, see below code[note: have not used @embed annotation not having jar not make difference]:

//import nestedclasswithenum.participanttype; import lombok.data; import lombok.noargsconstructor;   public class annotationbug {      nestedclasswithenum.participanttype type;       @data     @noargsconstructor     public static final class nestedclassnoenum {     }       @data     @noargsconstructor     public static final class nestedclasswithenum {         participanttype type;          public enum participanttype {             organizer,             registered,             wait_listed         }     } } 

reason seems related classloading of enumns , static classes. enums eagerly loaded static classes loaded lazily. java might trying stop @ compile time itself, guess.

edit: per discussion paul, above guess not correct.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -