Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8178701

Compile error with switch statement on protected enum defined in parent inner class

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      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.

      1. A.java
        0.1 kB
        Fairoz Matte
      2. D.java
        0.2 kB
        Fairoz Matte

        Activity

        Hide
        fmatte Fairoz Matte added a comment -
        Attached test cases passes in Eclipse, where as javac fail to compile with below reason
        ../jdk/9/ea/164/binaries/linux-x64/bin/javac foo/A.java bar/D.java
        bar/D.java:6: error: C.values() is defined in an inaccessible class or interface
        switch (arg) {
        ^
        1 error

        This issue exist for long time
        8 ea b02 - Fail
        8u121 - Fail
        9 ea b02 - Fail
        9 ea b164 - Fail
        Show
        fmatte Fairoz Matte added a comment - Attached test cases passes in Eclipse, where as javac fail to compile with below reason ../jdk/9/ea/164/binaries/linux-x64/bin/javac foo/A.java bar/D.java bar/D.java:6: error: C.values() is defined in an inaccessible class or interface switch (arg) { ^ 1 error This issue exist for long time 8 ea b02 - Fail 8u121 - Fail 9 ea b02 - Fail 9 ea b164 - Fail

          People

          • Assignee:
            vromero Vicente Arturo Romero Zaldivar
            Reporter:
            webbuggrp Webbug Group
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: