diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java index 16f26c836f8..d32b892eb54 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java @@ -5406,6 +5406,12 @@ public class JavacParser implements Parser { if (recordComponent) { mods = modifiersOpt(); + /* it could be that the user added a javadoc with the @deprecated tag, when analyzing this + * javadoc, javac will set the DEPRECATED flag. This is correct in most cases but not for + * record components and thus should be removed in that case. Any javadoc applied to + * record components is ignored + */ + mods.flags &= ~Flags.DEPRECATED; } else { mods = optFinal(Flags.PARAMETER | (lambdaParameter ? Flags.LAMBDA_PARAMETER : 0)); } diff --git a/test/langtools/tools/javac/records/RecordCompilationTests.java b/test/langtools/tools/javac/records/RecordCompilationTests.java index a8384ba4692..48b5cdd8588 100644 --- a/test/langtools/tools/javac/records/RecordCompilationTests.java +++ b/test/langtools/tools/javac/records/RecordCompilationTests.java @@ -2169,4 +2169,56 @@ class RecordCompilationTests extends CompilationTestCase { """ ); } + + @Test + void testDeprecatedJavadoc() { + String[] previousOptions = getCompileOptions(); + try { + setCompileOptions(new String[] {"-Xlint:deprecation"}); + assertOKWithWarning("compiler.warn.has.been.deprecated", + """ + record R( + /** + * @deprecated + */ + @Deprecated + int i + ) {} + class Client { + R r; + int j = r.i(); + } + """ + ); + assertOKWithWarning("compiler.warn.has.been.deprecated", + """ + record R( + @Deprecated + int i + ) {} + class Client { + R r; + int j = r.i(); + } + """ + ); + // javadoc tag only has no effect + assertOK( + """ + record R( + /** + * @deprecated + */ + int i + ) {} + class Client { + R r; + int j = r.i(); + } + """ + ); + } finally { + setCompileOptions(previousOptions); + } + } }