JDK-6594914 : @SuppressWarnings("deprecation") does not not work for the type of a variable
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0,7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,linux
  • CPU: generic,x86
  • Submitted: 2007-08-20
  • Updated: 2013-09-09
  • Resolved: 2011-03-08
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
7 b130Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
Compilation of this code:
package javaapplication1;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("deprecation")
        java.rmi.RMISecurityException ex;
    }

}

with "-Xlint:deprecation" produces:

/tmp/JavaApplication1/src/javaapplication1/Main.java:7: warning: [deprecation] java.rmi.RMISecurityException in java.rmi has been deprecated

This does not seem right, as JLS 9.6.1.5 says that:
"a Java compiler must not report any warning identified by one of S1, ... , S k if that warning would have been generated as a result of the annotated declaration or any of its parts"

Tested this on:
[snip]/jdk17/bin$ ./java -version
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b18)
Java HotSpot(TM) Server VM (build 1.7.0-ea-b18, mixed mode)
Another case where the @SuppressWarnings("deprecation") does not work correctly:
package javaapplication5;

@Deprecated
public class A {
}

package javaapplication5;

@SuppressWarnings("deprecation")
public class B extends A { //reports "A is deprecated" here

}

Comments
SUGGESTED FIX A webrev of this fix is available at the following URL: http://hg.openjdk.java.net/jdk7/tl/langtools/rev/899f7c3d9426
03-02-2011

EVALUATION The problem arises because the warnings should logically be detected (in MemberEnter, in this case), before it can be determined whether the warning should be suppressed (by SuppressWarnings.) The fix is probably to build a list of potential warnings and then filter the warnings once SuppressWarnings can be evaluated.
08-01-2008