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

static import fails to resolve interfaces on nested enums via import statements

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • 8
    • 6u26, 7
    • tools
    • x86
    • windows_7

    Description

      FULL PRODUCT VERSION :
      javac 1.6.0_27

      java version "1.6.0_27"
      Java(TM) SE Runtime Environment (build 1.6.0_27-b07)
      Java HotSpot(TM) Client VM (build 20.2-b06, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7

      A DESCRIPTION OF THE PROBLEM :
      If a class defines a nested enumeration which implements an interface from another package and you import that interface and also statically import the enumeration, then it will fail to build with an error indicating that it cannot find the symbol of the interface.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create the following interface:

      package pkg.subpkg;
      public interface ID { }

      And the following class:

      package pkg;

      import static pkg.Demo.DemoID.*;
      import pkg.subpkg.ID;

      public class Demo {

      public static enum DemoID implements ID { A, B, C }

      public static void main( String[] args ) {
      System.out.println( A );
      }
      }


      Now, try to compile and you will get the following error:
      pkg\Demo.java:8: cannot find symbol
      symbol: class ID
      location: class pkg.Demo
             public static enum DemoID implements ID { A, B, C }
      1 error


      However, if you don't use the static import and qualify references to the enum with the name of the enum, it will compile:

      System.out.println( DemoID.A );

      Or, if you fully qualify the name of ID in the enum declaration, it will compile:

      public static enum DemoID implements pkg.subpkg.ID { A, B, C }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect that imported interfaces would work regardless of whether they are applied to statically imported nested interface...

      I would expect that the example code I provided would compile.
      ACTUAL -
      pkg\Demo.java:8: cannot find symbol
      symbol: class ID
      location: class pkg.Demo
             public static enum DemoID implements ID { A, B, C }
      1 error

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      pkg\Demo.java:8: cannot find symbol
      symbol: class ID
      location: class pkg.Demo
             public static enum DemoID implements ID { A, B, C }
      1 error

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package pkg.subpkg;

      public interface ID { }

      --------------------------------------------------------

      package pkg;

      import static pkg.Demo.DemoID.*;
      import pkg.subpkg.ID;

      public class Demo {

      public static enum DemoID implements ID { A, B, C }

      public static void main( String[] args ) {
      System.out.println( A );
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      list the fully qualified class name for the interfaces you apply to nested enums which are statically imported.

      Attachments

        Issue Links

          Activity

            People

              mcimadamore Maurizio Cimadamore
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: