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

javac fails to compile an apparently valid class/interface combination

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 7
    • Fix Version/s: 8
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b43
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Backports

        Description

        SYNOPSIS
        --------
        javac fails to compile an apparently valid class/interface combination

        OPERATING SYSTEMS
        -----------------
        All

        FULL JDK VERSIONS
        -----------------
        All (tested on latest 5.0, 6, 7 and 8)

        PROBLEM DESCRIPTION
        -------------------
        javac fails to compile a enum type if it implements an interface which contains an enum with the same name as that of the implementor.

        In the testcase provided below, interface TestInterface has a enum type "enumA", while the class TestClass also has an enum type "enumA" which implements TestInterface. During compilation, javac appears to encounter a name resolution issue and an error occurs.

        The same code compiles with no issues under Eclipse, although this scenario does not seem to be explicitly described in the Java Language Specification.

        REPRODUCTION INSTRUCTIONS
        -------------------------
        1. Create the files as provided below
        2. Attempt to compile the class: javac TestClass.java

        Expected behaviour
        Class should compile with no errors

        Actual behaviour
        Compilation fails with the following error:

        TestClass.java:4: enumA(java.lang.String) has private access in TestInterface.enumA
                A("AAA");
                ^
        1 error

        TESTCASE
        --------
        ------------------------------------------------------------------------
        TestInterface.java
        ------------------------------------------------------------------------
        public interface TestInterface {
            public enum enumA implements TestInterface {
                I("III");

                private enumA(String s) {
                    System.out.println(s);
                }
            }
        }

        ------------------------------------------------------------------------
        TestClass.java
        ------------------------------------------------------------------------
        public final class TestClass {
            // This causes an error
            public enum enumA implements TestInterface {
                A("AAA");
               
                private enumA(String s) {
                    System.out.println(s);
                }
            }
               
            // This doesn't cause an error
            public enum enumB implements TestInterface {
                B("BBB");
               
                private enumB(String s) {
                    System.out.println(s);
                }
            }
        }

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  mcimadamore Maurizio Cimadamore
                  Reporter:
                  dkorbel David Korbel (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: