Code review request for 6908218 "java.lang.Deprecated should have explicit @Target meta-annotation"
Bruce Chapman
brucechapman at paradise.net.nz
Thu Jan 14 09:00:34 UTC 2010
Joe,
there is information about the rationale for the change in this email
but that information isn't in the bug report, Will it be put in the
commit message or bug report?
Bruce
Joseph D. Darcy wrote:
> Hello.
>
> Please review my patch to fix 6908218 "java.lang.Deprecated should
> have explicit @Target meta-annotation."
>
> For background, JSR 308 added two new enum constants to ElementType.
> ElementType constants are used in java.lang.annotation.Target
> meta-annotations to indicate what kind of elements an annotation is
> applicable to.
>
> If an annotation type does not have a @Target meta-annotation,
> annotations of the annotation type are allowed to be applied to all
> elements. Therefore, after JSR 308 added new ElementTypes,
> annotations without @Target meta-annotations can now be applied to
> more kinds of things, perhaps inappropriately given the semantics of
> the annotation.
>
> Conversely, annotations that do have a @Target meta-annotations might
> want to be applicable to the new locations.
>
> Two adjustments should be done to platform annotations: @Deprecated
> should get an explicit @Target meta-annotation and @SuppressWarnings
> should be applicable to another ElementType:
>
> --- old/src/share/classes/java/lang/Deprecated.java 2010-01-13
> 22:30:49.000000000 -0800
> +++ new/src/share/classes/java/lang/Deprecated.java 2010-01-13
> 22:30:49.000000000 -0800
> @@ -26,6 +26,7 @@
> package java.lang;
>
> import java.lang.annotation.*;
> +import static java.lang.annotation.ElementType.*;
>
> /**
> * A program element annotated @Deprecated is one that programmers
> @@ -38,5 +39,6 @@
> */
> @Documented
> @Retention(RetentionPolicy.RUNTIME)
> + at Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE,
> PARAMETER, TYPE})
> public @interface Deprecated {
> }
> --- old/src/share/classes/java/lang/SuppressWarnings.java
> 2010-01-13 22:30:50.000000000 -0800
> +++ new/src/share/classes/java/lang/SuppressWarnings.java
> 2010-01-13 22:30:49.000000000 -0800
> @@ -26,7 +26,6 @@
> package java.lang;
>
> import java.lang.annotation.*;
> -import java.lang.annotation.ElementType;
> import static java.lang.annotation.ElementType.*;
>
> /**
> @@ -45,7 +44,7 @@
> * @since 1.5
> * @author Josh Bloch
> */
> - at Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
> + at Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE,
> TYPE_PARAMETER})
> @Retention(RetentionPolicy.SOURCE)
> public @interface SuppressWarnings {
> /**
>
>
> For java.lang.Deprecated, the meta-annotation
> @Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE,
> PARAMETER, TYPE})
> includes all JDK 5/6 era locations annotations can be applied to.
> Therefore, with this list the locations @Deprecated can be applied
> will be unchanged from Java SE 6.
>
> JLSv3 mandates warnings be issued for the use of a deprecated "type,
> method, field, or constructor"
> (http://java.sun.com/docs/books/jls/third_edition/html/interfaces.html#9.6.1.6).
> Other permitted applications of an @Deprecated annotation must be
> ignored; "Use of the annotation @Deprecated on a local variable
> declaration or on a parameter declaration has no effect." Therefore,
> allowing @Deprecated on TYPE_PARAMETER or as a TYPE_USE would not be
> meaningful.
>
> Webrev at:
> http://cr.openjdk.java.net/~darcy/6908218.0/
>
> Thanks,
>
> -Joe
>
More information about the core-libs-dev
mailing list