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

add jsr175's java.lang.SuppressWarnings

XMLWordPrintable

    • b40
    • generic
    • solaris_8

      1.5.0's javac has more warnings than previous javac compilers, and these "lint-like" warnings are very useful. We plan to add more in subsequent releases. To encourage their use, there should be some way to disable a warning in a particular part of the program when the programmer knows that the warning is inappropriate for the given context. The obvious way to do this is with an annotation on the program element containing the code in question. I propose the following annotation type in java.lang:

      import java.lang.annotation.*;
      import static java.lang.annotation.ElementType.*;

      /**
      * Indicates that the named compiler warnings should be suppressed in
      * the annotated element (and in all program elements contained in the
      * annotated element). Note that the set of warnings suppressed in
      * a given element is a superset of the warnings suppressed in all
      * containing elements. For example, if you annotate a class to
      * suppress one warning and annotate a method to suppress another,
      * both warnings will be suppressed in the method.
      *
      * As a matter of style, programmers should always use this annotation
      * on the most deeply nested element where it is effective. If you want
      * to suppress a warning in a particular method, you should annotate that
      * method rather than its class.
      */
      @Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
      @Retention(RetentionPolicy.SOURCE)
      public @interface SuppressWarnings {
        /**
         * The set of warnings that are to be suppressed by the compiler
         * in the annotated element. Duplicate names are prohibited, and
         * will result in a compile-time error. The presence of unrecognized
         * warning names is <i>not</t> an error: compilers must ignore any
         * warnings they do not recognize. They are, however, free to emit a
         * warning if an annotation contains any unrecognized warning names.
         *
         * Compiler vendors should document the warning names they support
         * in conjunction with this annotation type, and are encouraged to
         * cooperate to ensure that the same names work across multiple
         * compilers.
         */
        String[] value();
      }

            gafter Neal Gafter (Inactive)
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: