JDK-8245664 : javac erroneously issues deprecation warning for use of a deprecated package
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-05-22
  • Updated: 2024-11-20
  • Resolved: 2020-09-03
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 16
16 b15Fixed
Related Reports
Relates :  
Relates :  
Description
The java.lang.Deprecated annotation type specification says,

«Use of the @Deprecated annotation on a local variable declaration or on a parameter declaration or a package declaration has no effect on the warnings issued by a compiler.»

Note however that @Deprecated is allowed on package declarations for reasons of backward compatibility.

https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/lang/Deprecated.html

JLS 9.6.4.6 specifies requirements that warnings be generated when certain deprecated program elements are mentioned, and packages are omitted from the list of program elements. 

https://docs.oracle.com/javase/specs/jls/se14/html/jls-9.html#jls-9.6.4.6

With these points in mind, consider the following source files:

p/package-info.java
===================

@Deprecated
package p;


p/P.java
========

package p;
public class P { }

q/Q.java
========
package q;
import p.*;
class Q {
    Class<?> c1 = P.class;    // **1**
    Class<?> c2 = p.P.class;  // **2**
}


Compiling all of files with "javac -Xlint:deprecation */*.java" results in:

==========
p/package-info.java:2: warning: [deprecation] @Deprecated annotation has no effect on this package declaration
package p;
        ^
q/Q.java:5: warning: [deprecation] p in  has been deprecated
    Class<?> c2 = p.P.class;
                  ^
2 warnings
==========

The first warning is probably ok, as it warns that the deprecation has no effect. (See JDK-8140772.)

The second warning is very strange, as it *IS* an effect of deprecating package p. Note that using a member of package p via on-demand import, as in line **1**, does not issue a warning. However, line **2**, which mentions package p as part of a full qualification of a class name, does issue a warning. Note also the malformed warning message.

This is rather strange, and it ought to be straightened out.
Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/c9455b1ee48d User: jlahoda Date: 2020-09-03 09:16:10 +0000
03-09-2020