JDK-6460147 : @SuppressWarnings("deprecation") does not work on fields
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2006-08-15
  • Updated: 2013-09-09
  • Resolved: 2013-09-09
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 7
7Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
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

Comments
The field/variable/method related usecases are covered by JDK-6594914, the class-extending-deprecated usecase is covered by JDK-6480588.
09-09-2013

EVALUATION This bug occurs because types of variable declarations (including method formal parameters/return type) are attributed during MemberEnter. At this stage the Xlint environment has not been augmented yet with the @SuppressWarning("deprecation") annotation - because of that, attributing type A will result in a deprecation warning.
27-04-2009

EVALUATION See also 6594914 for a similar but different manifestation of the same problem.
08-01-2008

EVALUATION This is probably because the field is analyzed during Enter, before the @SuppressWarning has been fully processed. The fix is probably to defer all warnings generated by deprecation until after @SuppressWarnings is fully available. -- i.e. we can detect the use of a deprecated item as now, but defer generating a warning until later.
17-08-2006

WORK AROUND None known, other than not using -Xlint:deprecated.
15-08-2006