JDK-4986254 : add jsr175's java.lang.SuppressWarnings
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_8
  • CPU: generic
  • Submitted: 2004-01-30
  • Updated: 2017-05-19
  • Resolved: 2004-02-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
Other
5.0 b40Fixed
Description
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();
}

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-beta2 FIXED IN: tiger-beta2 INTEGRATED IN: tiger-b40 tiger-beta2
2004-06-14

PUBLIC COMMENTS ...
2004-06-10

EVALUATION in progress. ###@###.### 2004-01-30
2004-01-30