-
Enhancement
-
Resolution: Fixed
-
P3
-
6u2
-
b42
-
x86
-
linux
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8085279 | emb-9 | Jan Lahoda | P3 | Resolved | Fixed | team |
$ 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
---%<---
- backported by
-
JDK-8085279 javac should not warn about imports of deprecated classes
- Resolved
- relates to
-
JDK-6480588 No way to suppress deprecation warnings when implementing deprecated interface
- Resolved
-
JDK-6460147 @SuppressWarnings("deprecation") does not work on fields
- Closed
-
JDK-8157773 javac gives warnings on import of deprecated items
- Open
-
JDK-6381698 Warn of decommissioning of apt
- Closed
-
JDK-6729835 Deprecated flag before import or package is not processed properly
- Closed
-
JDK-8032211 Don't issue deprecation warnings on import statements
- Closed
-
JDK-8042566 JEP 211: Elide Deprecation Warnings on Import Statements
- Closed