I encountered the following javac compilation failure where javac did not recognize annotations on a static nested class that had a public enum. Once I moved the enum out of the static nested class the compilation errors were resolved. Does anyone know why javac failed? Is this a java compiler bug? Or is there a java nuance that I am unaware of?
Below is a standalone test case.
Fails to 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 to point out:
1) Note the line number of the compilation failure. There is 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)