Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6460147

@SuppressWarnings("deprecation") does not work on fields

XMLWordPrintable

    • x86
    • linux

      ---%<---
      $ 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

            jlahoda Jan Lahoda
            jglick Jesse Glick (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: