FULL PRODUCT VERSION :
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) Client VM (build 25.121-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601] 32-bit
EXTRA RELEVANT SYSTEM CONFIGURATION :
javac 1.8.0_121
The issue was present at least as far back as javac 1.8.0_60.
A DESCRIPTION OF THE PROBLEM :
On the included source code, javac reports a compilation error. This error does not occur if any of the following modifications are made:
1. The code is compiled with the Eclipse java compiler instead of javac.
2. The switch statement is replaced with an explicit call to C.values() or arg.ordinal().
3. The enum C is moved to be inside the top-level class A instead of inside the inner class B.
4. The enum C is changed from protected to public.
As far as I can tell, this error should not occur according to the Java language spec.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a source file in the directory "foo" named "A.java" with the corresponding contents from the source code section.
2. Create a source file in the directory "bar" named "D.java" with the corresponding contents from the source code section.
3. Run "javac foo\A.java bar\D.java".
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The compilation succeeds without any errors.
ACTUAL -
javac reports the following error:
bar\D.java:8: error: values() in C is defined in an inaccessible class or interface
switch (arg) {
^
1 error
On similar code, javac will sometimes report an error on "ordinal() in Enum" instead of "values() in C". Regardless, the error occurs at the same location under the same conditions.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
// foo/A.java
package foo;
public class A {
public static class B {
protected enum C {
X, Y, Z
}
}
}
// bar/D.java
package bar;
import foo.A;
public class D extends A {
public static class E extends B {
public int doStuff(C arg) {
switch (arg) {
case X:
return 1;
case Y:
return 2;
default:
return 3;
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Move the enum C from the inner class B into the top-level class A.
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) Client VM (build 25.121-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601] 32-bit
EXTRA RELEVANT SYSTEM CONFIGURATION :
javac 1.8.0_121
The issue was present at least as far back as javac 1.8.0_60.
A DESCRIPTION OF THE PROBLEM :
On the included source code, javac reports a compilation error. This error does not occur if any of the following modifications are made:
1. The code is compiled with the Eclipse java compiler instead of javac.
2. The switch statement is replaced with an explicit call to C.values() or arg.ordinal().
3. The enum C is moved to be inside the top-level class A instead of inside the inner class B.
4. The enum C is changed from protected to public.
As far as I can tell, this error should not occur according to the Java language spec.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a source file in the directory "foo" named "A.java" with the corresponding contents from the source code section.
2. Create a source file in the directory "bar" named "D.java" with the corresponding contents from the source code section.
3. Run "javac foo\A.java bar\D.java".
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The compilation succeeds without any errors.
ACTUAL -
javac reports the following error:
bar\D.java:8: error: values() in C is defined in an inaccessible class or interface
switch (arg) {
^
1 error
On similar code, javac will sometimes report an error on "ordinal() in Enum" instead of "values() in C". Regardless, the error occurs at the same location under the same conditions.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
// foo/A.java
package foo;
public class A {
public static class B {
protected enum C {
X, Y, Z
}
}
}
// bar/D.java
package bar;
import foo.A;
public class D extends A {
public static class E extends B {
public int doStuff(C arg) {
switch (arg) {
case X:
return 1;
case Y:
return 2;
default:
return 3;
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Move the enum C from the inner class B into the top-level class A.