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

javac fails to compile inner class when secondary inner class is involved: "cannot find symbol"

XMLWordPrintable

    • sparc
    • solaris, solaris_10

      Javac fails to compile inner class, when a secondary inner class (inner class of the inner class)
      is imported first. It appears that importing a secondary inner class hides symbols in inner class.

      The problem can be cured by changing the sequence of import statements.

      The problem is easily reproducible.

      1. Testcase
      -----------
       The testcase consists of two files:
           abc/TestClass.java
           def/BaseClass.java

      % more abc/TestClass.java
      package abc;

      // Compile error with JavaSE 6, but not with JavaSE 1.4.2:

      import abc.TestClass.TTT.CCC;
      import def.BaseClass;

      public class TestClass
      {
              CCC ccc;

              public class TTT extends BaseClass {
                      public class CCC {
                              public CCC() {}
                      }
              }
      }

      % more def/BaseClass.java
      package def;

      public class BaseClass
      {
              public BaseClass() {}
      }


      2. Compile w/ 6u6
      -----------------
      % /jdk1.6.0_06/bin/javac def/BaseClass.java abc/TestClass.java
      abc/TestClass.java:12: cannot find symbol
      symbol : class BaseClass
      location: class abc.TestClass
              public class TTT extends BaseClass {
                                       ^
      1 error
      %

      3. Change source - works fine
      -----------------------------
       Change the sequence of import statements in abc/TestClass.java
       from
          import abc.TestClass.TTT.CCC;
          import def.BaseClass;
       to
          import def.BaseClass;
          import abc.TestClass.TTT.CCC;
       and compile again:

      % /jdk1.6.0_06/bin/javac def/BaseClass.java abc/TestClass.java
      %


      4. Problem reproducible w/ JDK 1.5.0
      ------------------------------------
      % /jdk1.5.0_17/bin/javac def/BaseClass.java abc/TestClass.java
      abc/TestClass.java:12: cannot find symbol
      symbol : class BaseClass
      location: class abc.TestClass
              public class TTT extends BaseClass {
                                       ^
      1 error
      %


      5. Problem not reproducible w/ J2SDK 1.4.2
      ------------------------------------------
      % /j2sdk1.4.2_17/bin/javac def/BaseClass.java abc/TestClass.java
      %

            mcimadamore Maurizio Cimadamore
            thlenz Thomas Lenz (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: