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

static import may hide other imports

XMLWordPrintable

    • x86_64
    • linux

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

      ADDITIONAL OS VERSION INFORMATION :
      Linux 3.2.45-0.6.acc.624.45.283.amzn1acc.x86_64 #1 SMP Fri Nov 21 22:39:25 UTC 2015 x86_64 x86_64 x86_64 GNU/linux

      A DESCRIPTION OF THE PROBLEM :
      See steps to reproduce below. There is a file which fails to compile, but which should succeed in compiling. The issue seems to be that placing a static import causes a symbol to no longer be visible to the compiler.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Attempt to compile the file listed in "Source code for an executable test case" via `javac Foo.java`

      This will result in a compile error (see "Error Messages" below for details).

      If you comment out the static import on line 3, the file will successfully compile.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      File should compile
      ACTUAL -
      File fails to compile.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Foo.java:8: error: cannot find symbol
          public static class Bar extends AbstractList<Object> {
                                          ^
        symbol: class AbstractList
        location: class Foo
      Foo.java:12: error: method does not override or implement a method from a supertype
              @Override
              ^
      Foo.java:18: error: method does not override or implement a method from a supertype
              @Override
              ^
      3 errors

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package test;

      // import static test.Foo.Bar.batz;
      import java.util.AbstractList;

      public class Foo
      {
          public static class Bar extends AbstractList<Object> {
              public static void batz() {
              }

              @Override
              public Iterable<Object> get(final int index)
              {
                  return null;
              }

              @Override
              public int size()
              {
                  return 0;
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      You can fully qualify the the AbstractList class:

      package test;

      import static test.Foo.Bar.batz;

      public class Foo
      {
          public static class Bar extends java.util.AbstractList<Object> {
              public static void batz() {
              }

              @Override
              public Iterable<Object> get(final int index)
              {
                  return null;
              }

              @Override
              public int size()
              {
                  return 0;
              }
          }
      }

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

              Created:
              Updated:
              Resolved: