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

@SuppressWarnings does not work in package-info.java yet is not rejected

    XMLWordPrintable

    Details

    • Subcomponent:
    • Understanding:
      Cause Known
    • CPU:
      x86
    • OS:
      linux

      Description

      Compile the following source tree using javac from b102 with -Xlint:

      ---%<--- testsuppwarnpkgs/package-info.java
      @SuppressWarnings("deprecation")
      package testsuppwarnpkgs;
      ---%<--- testsuppwarnpkgs/Main.java
      package testsuppwarnpkgs;
      import java.io.File;
      public class Main {
          public static void main(String[] args) throws Exception {
              new File("").toURL();
          }
      }
      ---%<---

      You get:

      ---%<---
      .../testsuppwarnpkgs/Main.java:5: warning: [deprecation] toURL() in java.io.File has been deprecated
              new File("").toURL();
      1 warning
      ---%<---

      1. Since a top-level class is "part of" a package, I would expect @SuppressWarnings on the package element to apply to it. But it seems it does not. It would be convenient if it did, e.g. if you wanted to ignore some warning irrelevant to you across an entire package, but not elsewhere in the compilation unit, or wanted to be able to compile all your sources with -Xlint and know that any exceptions are marked explicitly with annotations.

      (Cf. Javadoc of SuppressWarnings: "Note that the set of warnings suppressed in a given element is a superset of the warnings suppressed in all containing elements." Javadoc of PackageElement does not clarify whether it is a "container" or not.)

      2. SuppressWarnings is specified to be

      @Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})

      PACKAGE is not currently mentioned. So unless it is added, isn't it a bug in the compiler that it quietly accepts this annotation on a package element? I think it should be rejected. In fact it seems that more generally the compiler accepts any annotation on a package declaration regardless of its declared target kinds.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jjg Jonathan Gibbons
              Reporter:
              jglick Jesse Glick (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Imported:
                Indexed: