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

javac should not warn about imports of deprecated classes

    XMLWordPrintable

Details

    • b42
    • x86
    • linux
    • Verified

    Backports

      Description

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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: