8368864: Confusing error message (or wrong error) when record component has @deprecated Javadoc tag

Reviewed-by: jlahoda
This commit is contained in:
Vicente Romero 2026-02-26 15:18:54 +00:00
parent 3b8abd459f
commit 4f83d211d1
2 changed files with 58 additions and 0 deletions

View File

@ -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));
}

View File

@ -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);
}
}
}