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

Compiling depends on order of imports

    Details

    • Subcomponent:
    • Resolved In Build:
      b42
    • CPU:
      x86
    • OS:
      linux_ubuntu, windows_xp
    • Verification:
      Verified

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.7.0"
        Java(TM) SE Runtime Environment (build 1.7.0-b147)
        Java HosSpot(TM) Server VM (build 21.0-b17, mixed mode))

        ADDITIONAL OS VERSION INFORMATION :
        Linux Computer 2.6.38-11-generic #50-Ubuntu SMP Mon Sep 12 :21:18_14 UTC 2011 i686 i686 i386 GNU/Linux

        A DESCRIPTION OF THE PROBLEM :
        In some situations the order of imports in a class may be imported to let javac
        compile all classes:

        Let X be a class having an inner class X_1 extending some class Y in a
        different package. If a subtype of X_1 have to be imported (e.g. it has
        another inner class which is referenced) and it is imported before Y is
        imported, then X_1 is not compiled.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Create Z.java in package z with content:
        {{{
        package z;
        public class Z{}
        }}}

        Create A.java in package a with content:
        {{{
        package a;
        import a.A.B.C;
        import z.Z;
        public class A {
            class B extends Z {
                class C {}
            }
            class D {
                Class foo() {
                    return C.class;
                }
            }
        }
        }}}

        try to run: javac a/A.java

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        A compiles without problems.
        ACTUAL -
        A does not compile

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        a/A.java:5 error: cannot find symbol
            class B extends Z {
                                          ^
          symbol: class Z
          location: class A
        1 error

        REPRODUCIBILITY :
        This bug can be reproduced always.

        CUSTOMER SUBMITTED WORKAROUND :
        Reorder the imports or do not nest the classes.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  jlahoda Jan Lahoda
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  2 Vote for this issue
                  Watchers:
                  14 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: