changeset 3639:192d58e5d899

8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation Reviewed-by: mcimadamore
author sadayapalam
date Fri, 02 Sep 2016 07:49:15 +0530
parents f3c256cbcb58
children 595ae38c8f08
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java src/jdk.compiler/share/classes/com/sun/tools/javac/util/Options.java test/tools/javac/T4994049/DeprecatedYES.out test/tools/javac/danglingDep/DepX.out test/tools/javac/depDocComment/SuppressDepAnnWithSwitchTest.java test/tools/javac/depDocComment/SuppressDeprecation.java test/tools/javac/depDocComment/SuppressDeprecation.out test/tools/javac/depDocComment/SuppressDeprecation8.out test/tools/javac/depOverrides/doccomment/Test1.java test/tools/javac/depOverrides/doccomment/Test1A.out test/tools/javac/depOverrides/doccomment/Test1B.out test/tools/javac/depOverrides/doccomment/Test1B2.out test/tools/javac/depOverrides/doccomment/Test1B3.out test/tools/javac/depOverrides/doccomment/Test1I.out test/tools/javac/depOverrides/doccomment/Test2.java test/tools/javac/depOverrides/doccomment/Test2P.out test/tools/javac/depOverrides/doccomment/Test2Q.out test/tools/javac/depOverrides/doccomment/Test2R.out test/tools/javac/depOverrides/doccomment/Test3.out test/tools/javac/lint/Deprecation.out
diffstat 21 files changed, 172 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Thu Sep 01 13:21:52 2016 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Fri Sep 02 07:49:15 2016 +0530
@@ -359,6 +359,19 @@
         return (flags_field & DEPRECATED) != 0;
     }
 
+    public boolean isDeprecatableViaAnnotation() {
+        switch (getKind()) {
+            case LOCAL_VARIABLE:
+            case PACKAGE:
+            case PARAMETER:
+            case RESOURCE_VARIABLE:
+            case EXCEPTION_PARAMETER:
+                return false;
+            default:
+                return true;
+        }
+    }
+
     public boolean isStatic() {
         return
             (flags() & STATIC) != 0 ||
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Thu Sep 01 13:21:52 2016 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Fri Sep 02 07:49:15 2016 +0530
@@ -3192,7 +3192,7 @@
     }
 
     void checkDeprecatedAnnotation(DiagnosticPosition pos, Symbol s) {
-        if (lint.isEnabled(LintCategory.DEP_ANN) &&
+        if (lint.isEnabled(LintCategory.DEP_ANN) && s.isDeprecatableViaAnnotation() &&
             (s.flags() & DEPRECATED) != 0 &&
             !syms.deprecatedType.isErroneous() &&
             s.attribute(syms.deprecatedType.tsym) == null) {
@@ -3200,18 +3200,10 @@
                     pos, "missing.deprecated.annotation");
         }
         // Note: @Deprecated has no effect on local variables, parameters and package decls.
-        if (lint.isEnabled(LintCategory.DEPRECATION)) {
+        if (lint.isEnabled(LintCategory.DEPRECATION) && !s.isDeprecatableViaAnnotation()) {
             if (!syms.deprecatedType.isErroneous() && s.attribute(syms.deprecatedType.tsym) != null) {
-                switch (s.getKind()) {
-                    case LOCAL_VARIABLE:
-                    case PACKAGE:
-                    case PARAMETER:
-                    case RESOURCE_VARIABLE:
-                    case EXCEPTION_PARAMETER:
-                        log.warning(LintCategory.DEPRECATION, pos,
-                                "deprecated.annotation.has.no.effect", Kinds.kindName(s));
-                        break;
-                }
+                log.warning(LintCategory.DEPRECATION, pos,
+                        "deprecated.annotation.has.no.effect", Kinds.kindName(s));
             }
         }
     }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Options.java	Thu Sep 01 13:21:52 2016 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Options.java	Fri Sep 02 07:49:15 2016 +0530
@@ -26,6 +26,8 @@
 package com.sun.tools.javac.util;
 
 import java.util.*;
+
+import com.sun.tools.javac.code.Source;
 import com.sun.tools.javac.main.Option;
 import static com.sun.tools.javac.main.Option.*;
 
@@ -176,7 +178,17 @@
         // disabled
         return
             isSet(XLINT_CUSTOM, s) ||
-            (isSet(XLINT) || isSet(XLINT_CUSTOM, "all")) &&
+            (isSet(XLINT) || isSet(XLINT_CUSTOM, "all") || (s.equals("dep-ann") && depAnnOnByDefault())) &&
                 isUnset(XLINT_CUSTOM, "-" + s);
     }
+        // where
+        private boolean depAnnOnByDefault() {
+            String sourceName = get(Option.SOURCE);
+            Source source = null;
+            if (sourceName != null)
+                source = Source.lookup(sourceName);
+            if (source == null)
+                source = Source.DEFAULT;
+            return source.compareTo(Source.JDK1_9) >= 0;
+        }
 }
--- a/test/tools/javac/T4994049/DeprecatedYES.out	Thu Sep 01 13:21:52 2016 -0700
+++ b/test/tools/javac/T4994049/DeprecatedYES.out	Fri Sep 02 07:49:15 2016 +0530
@@ -1,4 +1,5 @@
+DeprecatedYES.java:12:10: compiler.warn.missing.deprecated.annotation
+- compiler.err.warnings.and.werror
 DeprecatedYES.java:18:10: compiler.warn.has.been.deprecated: foo(), A
-- compiler.err.warnings.and.werror
 1 error
-1 warning
+2 warnings
--- a/test/tools/javac/danglingDep/DepX.out	Thu Sep 01 13:21:52 2016 -0700
+++ b/test/tools/javac/danglingDep/DepX.out	Fri Sep 02 07:49:15 2016 +0530
@@ -1,2 +1,4 @@
+DepX.java:38:1: compiler.warn.missing.deprecated.annotation
 - compiler.note.deprecated.filename: RefX.java
 - compiler.note.deprecated.recompile
+1 warning
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/depDocComment/SuppressDepAnnWithSwitchTest.java	Fri Sep 02 07:49:15 2016 +0530
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8164073
+ * @summary Verify that -Xlint:-dep-ann suppresses warnings.
+ * @compile -Xlint:-dep-ann -Werror SuppressDepAnnWithSwitchTest.java
+ */
+
+public class SuppressDepAnnWithSwitchTest {
+    /** @deprecated */
+    int f;
+}
--- a/test/tools/javac/depDocComment/SuppressDeprecation.java	Thu Sep 01 13:21:52 2016 -0700
+++ b/test/tools/javac/depDocComment/SuppressDeprecation.java	Fri Sep 02 07:49:15 2016 +0530
@@ -1,10 +1,11 @@
 /**
  * @test  /nodynamiccopyright/
- * @bug 4216683 4346296 4656556 4785453
+ * @bug 4216683 4346296 4656556 4785453 8164073
  * @summary New rules for when deprecation messages are suppressed
  * @author gafter
  *
  * @compile/ref=SuppressDeprecation.out -Xlint:deprecation -XDrawDiagnostics SuppressDeprecation.java
+ * @compile/ref=SuppressDeprecation8.out -source 8 -Xlint:deprecation -XDrawDiagnostics SuppressDeprecation.java
  */
 
 /* Test for the contexts in which deprecations warnings should
--- a/test/tools/javac/depDocComment/SuppressDeprecation.out	Thu Sep 01 13:21:52 2016 -0700
+++ b/test/tools/javac/depDocComment/SuppressDeprecation.out	Fri Sep 02 07:49:15 2016 +0530
@@ -1,8 +1,20 @@
-SuppressDeprecation.java:82:10: compiler.warn.has.been.deprecated: g(), T
-SuppressDeprecation.java:83:14: compiler.warn.has.been.deprecated: g(), T
-SuppressDeprecation.java:84:9: compiler.warn.has.been.deprecated: var, T
-SuppressDeprecation.java:87:9: compiler.warn.has.been.deprecated: T(), T
-SuppressDeprecation.java:90:9: compiler.warn.has.been.deprecated: T(int), T
-SuppressDeprecation.java:98:1: compiler.warn.has.been.deprecated: T(), T
-SuppressDeprecation.java:130:17: compiler.warn.has.been.deprecated: X, compiler.misc.unnamed.package
-7 warnings
+SuppressDeprecation.java:29:9: compiler.warn.missing.deprecated.annotation
+SuppressDeprecation.java:33:10: compiler.warn.missing.deprecated.annotation
+SuppressDeprecation.java:38:10: compiler.warn.missing.deprecated.annotation
+SuppressDeprecation.java:48:5: compiler.warn.missing.deprecated.annotation
+SuppressDeprecation.java:53:5: compiler.warn.missing.deprecated.annotation
+SuppressDeprecation.java:67:10: compiler.warn.missing.deprecated.annotation
+SuppressDeprecation.java:74:9: compiler.warn.missing.deprecated.annotation
+SuppressDeprecation.java:80:10: compiler.warn.missing.deprecated.annotation
+SuppressDeprecation.java:83:10: compiler.warn.has.been.deprecated: g(), T
+SuppressDeprecation.java:84:14: compiler.warn.has.been.deprecated: g(), T
+SuppressDeprecation.java:85:9: compiler.warn.has.been.deprecated: var, T
+SuppressDeprecation.java:88:9: compiler.warn.has.been.deprecated: T(), T
+SuppressDeprecation.java:91:9: compiler.warn.has.been.deprecated: T(int), T
+SuppressDeprecation.java:99:1: compiler.warn.has.been.deprecated: T(), T
+SuppressDeprecation.java:124:9: compiler.warn.missing.deprecated.annotation
+SuppressDeprecation.java:103:1: compiler.warn.missing.deprecated.annotation
+SuppressDeprecation.java:129:1: compiler.warn.missing.deprecated.annotation
+SuppressDeprecation.java:131:17: compiler.warn.has.been.deprecated: X, compiler.misc.unnamed.package
+SuppressDeprecation.java:135:1: compiler.warn.missing.deprecated.annotation
+19 warnings
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/depDocComment/SuppressDeprecation8.out	Fri Sep 02 07:49:15 2016 +0530
@@ -0,0 +1,9 @@
+- compiler.warn.source.no.bootclasspath: 1.8
+SuppressDeprecation.java:83:10: compiler.warn.has.been.deprecated: g(), T
+SuppressDeprecation.java:84:14: compiler.warn.has.been.deprecated: g(), T
+SuppressDeprecation.java:85:9: compiler.warn.has.been.deprecated: var, T
+SuppressDeprecation.java:88:9: compiler.warn.has.been.deprecated: T(), T
+SuppressDeprecation.java:91:9: compiler.warn.has.been.deprecated: T(int), T
+SuppressDeprecation.java:99:1: compiler.warn.has.been.deprecated: T(), T
+SuppressDeprecation.java:131:17: compiler.warn.has.been.deprecated: X, compiler.misc.unnamed.package
+8 warnings
--- a/test/tools/javac/depOverrides/doccomment/Test1.java	Thu Sep 01 13:21:52 2016 -0700
+++ b/test/tools/javac/depOverrides/doccomment/Test1.java	Fri Sep 02 07:49:15 2016 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,11 +26,11 @@
  * @bug 5086088
  * @summary check warnings generated when overriding deprecated methods
  *
- * @compile/ref=empty    -XDrawDiagnostics -Xlint:deprecation I.java
+ * @compile/ref=Test1I.out   -XDrawDiagnostics -Xlint:deprecation I.java
  * @compile/ref=Test1A.out  -XDrawDiagnostics -Xlint:deprecation A.java
  * @compile/ref=Test1B.out  -XDrawDiagnostics -Xlint:deprecation B.java
  * @compile/ref=Test1B2.out -XDrawDiagnostics -Xlint:deprecation B2.java
- * @compile/ref=empty    -XDrawDiagnostics -Xlint:deprecation B3.java
+ * @compile/ref=Test1B3.out    -XDrawDiagnostics -Xlint:deprecation B3.java
  * @compile/ref=empty    -XDrawDiagnostics -Xlint:deprecation Test1.java
  */
 
--- a/test/tools/javac/depOverrides/doccomment/Test1A.out	Thu Sep 01 13:21:52 2016 -0700
+++ b/test/tools/javac/depOverrides/doccomment/Test1A.out	Fri Sep 02 07:49:15 2016 +0530
@@ -1,4 +1,10 @@
 A.java:13:36: compiler.warn.has.been.deprecated: iDep_aUnd_bInh(), I
 A.java:12:36: compiler.warn.has.been.deprecated: iDep_aUnd_bUnd(), I
 A.java:11:36: compiler.warn.has.been.deprecated: iDep_aUnd_bDep(), I
-3 warnings
+A.java:8:36: compiler.warn.missing.deprecated.annotation
+A.java:9:36: compiler.warn.missing.deprecated.annotation
+A.java:10:36: compiler.warn.missing.deprecated.annotation
+A.java:17:36: compiler.warn.missing.deprecated.annotation
+A.java:18:36: compiler.warn.missing.deprecated.annotation
+A.java:19:36: compiler.warn.missing.deprecated.annotation
+9 warnings
--- a/test/tools/javac/depOverrides/doccomment/Test1B.out	Thu Sep 01 13:21:52 2016 -0700
+++ b/test/tools/javac/depOverrides/doccomment/Test1B.out	Fri Sep 02 07:49:15 2016 +0530
@@ -1,4 +1,10 @@
 B.java:15:36: compiler.warn.has.been.deprecated: iDep_aInh_bUnd(), I
+B.java:8:36: compiler.warn.missing.deprecated.annotation
 B.java:9:36: compiler.warn.has.been.deprecated: iDep_aDep_bUnd(), A
+B.java:11:36: compiler.warn.missing.deprecated.annotation
+B.java:14:36: compiler.warn.missing.deprecated.annotation
+B.java:17:36: compiler.warn.missing.deprecated.annotation
 B.java:18:36: compiler.warn.has.been.deprecated: iUnd_aDep_bUnd(), A
-3 warnings
+B.java:20:36: compiler.warn.missing.deprecated.annotation
+B.java:23:36: compiler.warn.missing.deprecated.annotation
+9 warnings
--- a/test/tools/javac/depOverrides/doccomment/Test1B2.out	Thu Sep 01 13:21:52 2016 -0700
+++ b/test/tools/javac/depOverrides/doccomment/Test1B2.out	Fri Sep 02 07:49:15 2016 +0530
@@ -2,6 +2,12 @@
 B2.java:7:10: compiler.warn.has.been.deprecated: iDep_aUnd_bInh(), I
 B2.java:12:36: compiler.warn.has.been.deprecated: iDep_aUnd_bUnd(), I
 B2.java:9:36: compiler.warn.has.been.deprecated: iDep_aDep_bUnd(), I
+B2.java:8:36: compiler.warn.missing.deprecated.annotation
 B2.java:9:36: compiler.warn.has.been.deprecated: iDep_aDep_bUnd(), A
+B2.java:11:36: compiler.warn.missing.deprecated.annotation
+B2.java:14:36: compiler.warn.missing.deprecated.annotation
+B2.java:17:36: compiler.warn.missing.deprecated.annotation
 B2.java:18:36: compiler.warn.has.been.deprecated: iUnd_aDep_bUnd(), A
-6 warnings
+B2.java:20:36: compiler.warn.missing.deprecated.annotation
+B2.java:23:36: compiler.warn.missing.deprecated.annotation
+12 warnings
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/depOverrides/doccomment/Test1B3.out	Fri Sep 02 07:49:15 2016 +0530
@@ -0,0 +1,8 @@
+B3.java:32:36: compiler.warn.missing.deprecated.annotation
+B3.java:35:36: compiler.warn.missing.deprecated.annotation
+B3.java:38:36: compiler.warn.missing.deprecated.annotation
+B3.java:41:36: compiler.warn.missing.deprecated.annotation
+B3.java:44:36: compiler.warn.missing.deprecated.annotation
+B3.java:47:36: compiler.warn.missing.deprecated.annotation
+B3.java:31:10: compiler.warn.missing.deprecated.annotation
+7 warnings
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/depOverrides/doccomment/Test1I.out	Fri Sep 02 07:49:15 2016 +0530
@@ -0,0 +1,9 @@
+I.java:30:36: compiler.warn.missing.deprecated.annotation
+I.java:31:36: compiler.warn.missing.deprecated.annotation
+I.java:32:36: compiler.warn.missing.deprecated.annotation
+I.java:33:36: compiler.warn.missing.deprecated.annotation
+I.java:34:36: compiler.warn.missing.deprecated.annotation
+I.java:35:36: compiler.warn.missing.deprecated.annotation
+I.java:36:36: compiler.warn.missing.deprecated.annotation
+I.java:37:36: compiler.warn.missing.deprecated.annotation
+8 warnings
--- a/test/tools/javac/depOverrides/doccomment/Test2.java	Thu Sep 01 13:21:52 2016 -0700
+++ b/test/tools/javac/depOverrides/doccomment/Test2.java	Fri Sep 02 07:49:15 2016 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,7 @@
  * @bug 5086088
  * @summary check warnings generated when overriding deprecated methods
  *
- * @compile/ref=empty   -XDrawDiagnostics -Xlint:deprecation P.java
+ * @compile/ref=Test2P.out -XDrawDiagnostics -Xlint:deprecation P.java
  * @compile/ref=Test2Q.out -XDrawDiagnostics -Xlint:deprecation Q.java
  * @compile/ref=Test2R.out -XDrawDiagnostics -Xlint:deprecation R.java
  * @compile/ref=empty   -XDrawDiagnostics -Xlint:deprecation Test2.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/depOverrides/doccomment/Test2P.out	Fri Sep 02 07:49:15 2016 +0530
@@ -0,0 +1,10 @@
+P.java:30:36: compiler.warn.missing.deprecated.annotation
+P.java:31:36: compiler.warn.missing.deprecated.annotation
+P.java:32:36: compiler.warn.missing.deprecated.annotation
+P.java:33:36: compiler.warn.missing.deprecated.annotation
+P.java:34:36: compiler.warn.missing.deprecated.annotation
+P.java:35:36: compiler.warn.missing.deprecated.annotation
+P.java:36:36: compiler.warn.missing.deprecated.annotation
+P.java:37:36: compiler.warn.missing.deprecated.annotation
+P.java:38:36: compiler.warn.missing.deprecated.annotation
+9 warnings
--- a/test/tools/javac/depOverrides/doccomment/Test2Q.out	Thu Sep 01 13:21:52 2016 -0700
+++ b/test/tools/javac/depOverrides/doccomment/Test2Q.out	Fri Sep 02 07:49:15 2016 +0530
@@ -1,4 +1,10 @@
+Q.java:8:36: compiler.warn.missing.deprecated.annotation
+Q.java:9:36: compiler.warn.missing.deprecated.annotation
+Q.java:10:36: compiler.warn.missing.deprecated.annotation
 Q.java:11:36: compiler.warn.has.been.deprecated: pDep_qUnd_rDep(), P
 Q.java:12:36: compiler.warn.has.been.deprecated: pDep_qUnd_rUnd(), P
 Q.java:13:36: compiler.warn.has.been.deprecated: pDep_qUnd_rInh(), P
-3 warnings
+Q.java:17:36: compiler.warn.missing.deprecated.annotation
+Q.java:18:36: compiler.warn.missing.deprecated.annotation
+Q.java:19:36: compiler.warn.missing.deprecated.annotation
+9 warnings
--- a/test/tools/javac/depOverrides/doccomment/Test2R.out	Thu Sep 01 13:21:52 2016 -0700
+++ b/test/tools/javac/depOverrides/doccomment/Test2R.out	Fri Sep 02 07:49:15 2016 +0530
@@ -1,4 +1,10 @@
+R.java:8:36: compiler.warn.missing.deprecated.annotation
 R.java:9:36: compiler.warn.has.been.deprecated: pDep_qDep_rUnd(), Q
+R.java:11:36: compiler.warn.missing.deprecated.annotation
+R.java:14:36: compiler.warn.missing.deprecated.annotation
 R.java:15:36: compiler.warn.has.been.deprecated: pDep_qInh_rUnd(), P
+R.java:17:36: compiler.warn.missing.deprecated.annotation
 R.java:18:36: compiler.warn.has.been.deprecated: pUnd_qDep_rUnd(), Q
-3 warnings
+R.java:20:36: compiler.warn.missing.deprecated.annotation
+R.java:23:36: compiler.warn.missing.deprecated.annotation
+9 warnings
--- a/test/tools/javac/depOverrides/doccomment/Test3.out	Thu Sep 01 13:21:52 2016 -0700
+++ b/test/tools/javac/depOverrides/doccomment/Test3.out	Fri Sep 02 07:49:15 2016 +0530
@@ -1,2 +1,3 @@
+Test3.java:11:14: compiler.warn.missing.deprecated.annotation
 Test3.java:18:1: compiler.warn.has.been.deprecated: m(), LibInterface
-1 warning
+2 warnings
--- a/test/tools/javac/lint/Deprecation.out	Thu Sep 01 13:21:52 2016 -0700
+++ b/test/tools/javac/lint/Deprecation.out	Fri Sep 02 07:49:15 2016 +0530
@@ -1,4 +1,5 @@
+Deprecation.java:11:1: compiler.warn.missing.deprecated.annotation
+- compiler.err.warnings.and.werror
 Deprecation.java:14:17: compiler.warn.has.been.deprecated: A, compiler.misc.unnamed.package
-- compiler.err.warnings.and.werror
 1 error
-1 warning
+2 warnings