JDK-6598104 : javac should not warn about imports of deprecated classes
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6u2
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2007-08-28
  • Updated: 2021-03-20
  • Resolved: 2014-11-24
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 b42Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
---%<---
$ cat */*.java; javac -version -Xlint:deprecation */*.java
package p1;
@Deprecated public class A {}
package p2;
import p1.A;
class B {}
package p3;
class C {
    p1.A a;
}
package p4;
import p1.A;
class D {
    A a;
}
javac 1.6.0_02
p2/B.java:2: warning: [deprecation] p1.A in p1 has been deprecated
import p1.A;
         ^
p3/C.java:3: warning: [deprecation] p1.A in p1 has been deprecated
    p1.A a;
      ^
p4/D.java:2: warning: [deprecation] p1.A in p1 has been deprecated
import p1.A;
         ^
p4/D.java:4: warning: [deprecation] p1.A in p1 has been deprecated
    A a;
    ^
4 warnings
---%<---

1. In D.java, p1.A is only really "used" once (as the type of a field) yet two warnings are issued. This seems unnecessary.

2. In B.java, p1.A is not really used at all (will not appear in B.class), yet a warning is still issued. I would think the more useful warning would be that there is an unused import; the fact that the imported class happens to be deprecated is secondary.

My suggested output from javac, assuming a hypothetical new lint category 'imports' for unused imports (which all modern IDEs already show as some kind of warning):

---%<---
$ javac -Xlint:deprecation,imports */*.java
p2/B.java:2: warning: [imports] import p1.A is unused
import p1.A;
       ^
p3/C.java:3: warning: [deprecation] p1.A in p1 has been deprecated
    p1.A a;
      ^
p4/D.java:4: warning: [deprecation] p1.A in p1 has been deprecated
    A a;
    ^
3 warnings
---%<---

Comments
See related comment: http://mail.openjdk.java.net/pipermail/compiler-dev/2014-October/009069.html
17-11-2014