JDK-6481080 : (ann) @Deprecated annotation has no effect on packages
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-10-12
  • Updated: 2017-05-16
  • Resolved: 2015-01-08
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 Availability Release.

To download the current JDK release, click here.
JDK 9
9 b46Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Sub Tasks
JDK-8068543 :  
JDK-8141359 :  
Description
The documentation of the @Deprecated annotation says:
"A program element annotated @Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists. Compilers warn when a deprecated program element is used or overridden in non-deprecated code."

Packages are program elements (as implicitly defined by the ElementType enum) and the @Deprecated annotation does not have a @Target meta-annotation that prevents it from being applied to packages.  So the second quoted sentence above says the compiler will warn if you use a package that is deprecated.  This is done by adding a @Deprecated annotation to the package declaration in a package-info.java in the package directory.  But it does not in fact have any effect.

The meaning of "using" a package is clear.  Referencing any class within a package is a use of the package, just as referencing any field or method in a class is a use of the class and will draw a warning if the class is deprecated.

Either the compiler should issue warnings when a deprecated package is referenced, or the quoted text should be modified.

Comments
Review thread: http://mail.openjdk.java.net/pipermail/core-libs-dev/2015-January/030636.html
06-01-2015

Since @Deprecated has explicitly listed its targets since Java SE 7, it would be appropriate for JLS 9.6.4.6 to ensure that something is said about @Deprecated in each and every listed target. In particular, this means that "Use of the @Deprecated annotation on a local variable declaration or on a parameter declaration has no effect." should also mention a package declaration.
06-01-2015

With other work going on related to deprecation (JDK-8042566), at least one of the library specification for java.lang.Deprecated and the JLS section covering that annotation should be updated to explicitly discuss its effect (or lack thereof) when used on a package.
21-11-2014

EVALUATION The JLS says: "A program element annotated @Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists. A Java compiler must produce a warning when a deprecated type, method, field, or constructor is used (overridden, invoked, or referenced by name) [...]" Notice that @Deprecation does not apply to to nested elements. For example, the members of a deprecated class are not deprecated them selves but you will have a hard time using them without mentioning the deprecated class so you will get a deprecation warning anyways. The JLS explicitly mentions the program elements which must cause a warning: "type, method, field, or constructor". A package is not a type. There is a caveat: for modeling convenience javax.lang.model.element.PackageElement has an asType method. This, however, does not change the JLS terminology in which a package is not a type. Perhaps the documentation for java.lang.Deprecated should be clarified. I'm reassigning this to classes_lang for consideration.
13-10-2006