Details
-
Bug
-
Resolution: Duplicate
-
P4
-
5.0
-
x86
-
linux
Description
---%<---
$ rm *.class; cat A.java B.java C.java; javac C.java; javac -version -Xlint:deprecation C.java
@Deprecated
public class A {}
@Deprecated
public class B {}
public class C {
@SuppressWarnings("deprecation")
A a;
@SuppressWarnings("deprecation")
void m() {
B b = null;
}
}
javac 1.5.0_08
C.java:3: warning: [deprecation] A in unnamed package has been deprecated
A a;
^
1 warning
---%<---
It seems that @SuppressWarnings("deprecation") works fine for local variables but has no effect on fields whose type is deprecated. Adding @SuppressWarnings("deprecation") to the class does not help either.
Same bug in JDK 6 b95.
Another more comprhensive test case:
@Deprecated
class A {}
class B {
@SuppressWarnings("deprecation")
A a;
@SuppressWarnings("deprecation")
A m(A a) {return null;}
@SuppressWarnings("deprecation")
class C extends A {}
}
Which gives the following warnings:
TestX.java:6: warning: [deprecation] A in unnamed package has been deprecated
A a;
^
TestX.java:9: warning: [deprecation] A in unnamed package has been deprecated
A m(A a) {return null;}
^
TestX.java:9: warning: [deprecation] A in unnamed package has been deprecated
A m(A a) {return null;}
^
TestX.java:12: warning: [deprecation] A in unnamed package has been deprecated
class C extends A {}
^
4 warnings
$ rm *.class; cat A.java B.java C.java; javac C.java; javac -version -Xlint:deprecation C.java
@Deprecated
public class A {}
@Deprecated
public class B {}
public class C {
@SuppressWarnings("deprecation")
A a;
@SuppressWarnings("deprecation")
void m() {
B b = null;
}
}
javac 1.5.0_08
C.java:3: warning: [deprecation] A in unnamed package has been deprecated
A a;
^
1 warning
---%<---
It seems that @SuppressWarnings("deprecation") works fine for local variables but has no effect on fields whose type is deprecated. Adding @SuppressWarnings("deprecation") to the class does not help either.
Same bug in JDK 6 b95.
Another more comprhensive test case:
@Deprecated
class A {}
class B {
@SuppressWarnings("deprecation")
A a;
@SuppressWarnings("deprecation")
A m(A a) {return null;}
@SuppressWarnings("deprecation")
class C extends A {}
}
Which gives the following warnings:
TestX.java:6: warning: [deprecation] A in unnamed package has been deprecated
A a;
^
TestX.java:9: warning: [deprecation] A in unnamed package has been deprecated
A m(A a) {return null;}
^
TestX.java:9: warning: [deprecation] A in unnamed package has been deprecated
A m(A a) {return null;}
^
TestX.java:12: warning: [deprecation] A in unnamed package has been deprecated
class C extends A {}
^
4 warnings
Attachments
Issue Links
- duplicates
-
JDK-6594914 @SuppressWarnings("deprecation") does not not work for the type of a variable
- Closed
- relates to
-
JDK-6480588 No way to suppress deprecation warnings when implementing deprecated interface
- Resolved
-
JDK-6480588 No way to suppress deprecation warnings when implementing deprecated interface
- Resolved
-
JDK-6594914 @SuppressWarnings("deprecation") does not not work for the type of a variable
- Closed
-
JDK-6598104 javac should not warn about imports of deprecated classes
- Closed