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

static import bug with more than 2 imports of the same name

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6
    • tools
    • x86
    • windows_2000

      J2SE Version (please include all output from java -version flag):
        java version "1.6.0-ea"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b38)
        Java HotSpot(TM) Client VM (build 1.6.0-ea-b38, mixed mode, sharing)

      Does this problem occur on J2SE 1.4.x or 5.0.x ? Yes / No (pick one)
        NA to 1.4.x, occurs on 5.0.x

      Operating System Configuration Information (be specific):
        Microsoft Windows 2000 [Version 5.00.2195]

      Hardware Configuration Information (be specific):
        Desktop

      Bug Description:
        static import bug with more than 2 imports of the same name

      According to the spec the following code should cause an Ambiguity error.
        Instead the ordering of the imports affects the output and the compilation.

        I have made the problem look obvious, however in complex programs with many static
        imports including imports such as:

      import static javax.swing.table.DefaultTableCellRenderer.*;
      import static java.awt.BorderLayout.*;
      import static javax.swing.SwingConstants.*;

        calling container.add(component, NORTH) will fail with a Runtime Error, and the
        problem is not as easy to find.

        Changing the order of the imports to
       
        import static javax.swing.SwingConstants.*;
        import static java.awt.BorderLayout.*;
        import static javax.swing.SwingConstants.*;
        import static java.awt.BorderLayout.*;

        will give the Ambiguity error as required.

        Changing the order of the imports to

        import static javax.swing.SwingConstants.*;
        import static javax.swing.SwingConstants.*;
        import static java.awt.BorderLayout.*;
        import static java.awt.BorderLayout.*;

        will change the results of the output from 1 to North.

      Steps to Reproduce (be specific):
        compile the following code

      import static java.awt.BorderLayout.*;
      import static java.awt.BorderLayout.*;
      import static javax.swing.SwingConstants.*;
      import static javax.swing.SwingConstants.*;

      public class Test {
       public static void main(String s[]) {
         System.out.println(NORTH);
       }
      }

            Unassigned Unassigned
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: