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

Compilation fails for class that has inner enum that implements in interface if that class import static the enum values

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_111"
      Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux ran 4.4.0-72-generic #93-Ubuntu SMP Fri Mar 31 14:07:41 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      Compilation fails with "error: cannot find symbol" if you have the following structure:
      package1/Intf.java - an interface
      package2/User.java - a class that:
      1. has an inner enum X that implements Intf
      2. uses the enum values X by declaring "import static X.*"

      If X is a class, compilation will succeed. If Intf is placed in package2 (with the user class), compilation will succeed. If the import static is omitted and the enum X is fully specified, compilation will succeed. If the enum is made a top-level class, compilation will succeed.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See source. Running compile with:
      "javac compiler_issue_intf/*.java compiler_issue_user/*.java"

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      compilation to succeed
      ACTUAL -
      compilation fails with "error: cannot find symbol"

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      compiler_issue_user/User.java:13: error: cannot find symbol
          enum MyEnym implements Intf {
                                 ^
        symbol: class Intf
        location: class User
      1 error


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Create folder structure:
      mkdir compiler_issue_intf
      mkdir compiler_issue_user

      Place Intf.java in compiler_issue_intf:
      ---
      package compiler_issue_intf;

      public interface Intf {
          String getName();
      }
      ---

      Place User.java in compiler_issue_user:
      ---
      package compiler_issue_user;

      import static compiler_issue_user.User.MyEnym.VALUE1;

      import compiler_issue_intf.Intf;

      public class User {

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

          enum MyEnym implements Intf {
              VALUE1,
              VALUE2;

              public String getName() {
                  return name();
              }

          }
      }
      ---

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

      CUSTOMER SUBMITTED WORKAROUND :
      If X is a class, compilation will succeed. If Intf is placed in package2 (with the user class), compilation will succeed. If the import static is omitted and the enum X is fully specified, compilation will succeed. If the enum is made a top-level class, compilation will succeed.

            jlahoda Jan Lahoda
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: