8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
Reviewed-by: mcimadamore
This commit is contained in:
parent
4017bf5f7a
commit
876bb73271
langtools
src/jdk.compiler/share/classes/com/sun/tools/javac
test/tools/javac
T4994049
danglingDep
depDocComment
SuppressDepAnnWithSwitchTest.javaSuppressDeprecation.javaSuppressDeprecation.outSuppressDeprecation8.out
depOverrides/doccomment
Test1.javaTest1A.outTest1B.outTest1B2.outTest1B3.outTest1I.outTest2.javaTest2P.outTest2Q.outTest2R.outTest3.out
lint
@ -359,6 +359,19 @@ public abstract class Symbol extends AnnoConstruct implements Element {
|
||||
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 ||
|
||||
|
@ -3192,7 +3192,7 @@ public class Check {
|
||||
}
|
||||
|
||||
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 @@ public class Check {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 @@ public class Options {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
DeprecatedYES.java:18:10: compiler.warn.has.been.deprecated: foo(), A
|
||||
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
|
||||
1 error
|
||||
1 warning
|
||||
2 warnings
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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
|
||||
*/
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -2,6 +2,12 @@ B2.java:15:36: compiler.warn.has.been.deprecated: iDep_aInh_bUnd(), I
|
||||
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
|
||||
|
@ -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
|
@ -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
|
@ -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
|
||||
|
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,4 +1,5 @@
|
||||
Deprecation.java:14:17: compiler.warn.has.been.deprecated: A, compiler.misc.unnamed.package
|
||||
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
|
||||
1 error
|
||||
1 warning
|
||||
2 warnings
|
||||
|
Loading…
x
Reference in New Issue
Block a user