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

"import static" accessibility rules for symbols different for no reason

    XMLWordPrintable

Details

    • 5.0
    • b71
    • generic
    • generic
    • Verified

    Description

      javac should use the same accessiblity rules for symbols imported using
      static import as for resolving symbols as "normal" symbol references,
      but it doesn't, and this is very surprising to users.

      In the unlikely event that they should be different, the error
      should be reported in the static import statement, not the symbol reference.

      Self-explanatory shell transcript follows:

      $ cat StaticImportAccess.java
      import static java.util.zip.ZipFile.ENDSIG;

      public class StaticImportAccess {
          public static long i = ENDSIG;
      }
      $ javac -source 1.5 StaticImportAccess.java
      StaticImportAccess.java:4: ENDSIG in java.util.zip.ZipConstants is defined in an inaccessible class or interface
          public static long i = ENDSIG;
                                 ^
      1 error
      zsh: exit 1 jver 1.6.0 javac -source 1.5 StaticImportAccess.java
      $ cat NormalAccess.java
      public class NormalAccess {
          public static long i = java.util.zip.ZipFile.ENDSIG;
      }
      $ javac -source 1.5 NormalAccess.java
      $
      ###@###.### 2005-2-05 19:45:21 GMT

      Attachments

        Issue Links

          Activity

            People

              ahe Peter Ahe
              martin Martin Buchholz
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: