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

@Retention(SOURCE) for @Deprecated annotation is confusing

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs
    • None
    • generic
    • generic

      The annotation @java.lang.Deprecated is defined with @Retention(SOURCE). This is confusing, since SOURCE means "Annotations are to be discarded by the compiler." But in fact the compiler does not discard @Deprecated annotations. They are in fact recorded in the generated class file, but using the "Deprecated" attribute, not an annotation. This distinction is subtle and likely to cause head-scratching. It would be better if either:
      (a) @Deprecated were defined with @Retention(CLASS), meaning "Annotations are to be recorded in the class file by the compiler" (but in fact not recorded *as an annotation*, and the documentation could state this), or
      (b) the documentation for @Deprecated were updated to say, e.g., "The @Retention of this annotation is SOURCE even though it does affect the compiled class file, because deprecation is not recorded as an annotation but as a special attribute in the class file."

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: