Skip to content

Commit ac15d64

Browse files
Vicente Romerobsrbndvicente-romero-oracle
committed
8241151: Incorrect lint warning for no definition of serialVersionUID in a record
Co-authored-by: Bernard Blaser <bsrbnd@gmail.com> Co-authored-by: Vicente Romero <vicente.romero@oracle.com> Reviewed-by: jjg
1 parent d25b03e commit ac15d64

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5348,8 +5348,8 @@ private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c) {
53485348
}
53495349

53505350
if (svuid == null) {
5351-
log.warning(LintCategory.SERIAL,
5352-
tree.pos(), Warnings.MissingSVUID(c));
5351+
if (!c.isRecord())
5352+
log.warning(LintCategory.SERIAL, tree.pos(), Warnings.MissingSVUID(c));
53535353
return;
53545354
}
53555355

test/langtools/tools/javac/records/RecordCompilationTests.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/**
2727
* RecordCompilationTests
2828
*
29-
* @test 8250629 8252307 8247352
29+
* @test 8250629 8252307 8247352 8241151
3030
* @summary Negative compilation tests, and positive compilation (smoke) tests for records
3131
* @library /lib/combo /tools/lib /tools/javac/lib
3232
* @modules
@@ -145,8 +145,10 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
145145
}
146146
}
147147

148+
boolean useAP;
149+
148150
public RecordCompilationTests() {
149-
boolean useAP = System.getProperty("useAP") == null ? false : System.getProperty("useAP").equals("true");
151+
useAP = System.getProperty("useAP", "false").equals("true");
150152
setDefaultFilename("R.java");
151153
setCompileOptions(useAP ? PREVIEW_OPTIONS_WITH_AP : PREVIEW_OPTIONS);
152154
System.out.println(useAP ? "running all tests using an annotation processor" : "running all tests without annotation processor");
@@ -1664,4 +1666,20 @@ record R<T>(T t[]) {}
16641666
"""
16651667
);
16661668
}
1669+
1670+
public void testNoWarningForSerializableRecords() {
1671+
if (!useAP) {
1672+
/* dont execute this test when the default annotation processor is on as it will fail due to
1673+
* spurious warnings
1674+
*/
1675+
appendCompileOptions("-Werror", "-Xlint:serial");
1676+
assertOK(
1677+
"""
1678+
import java.io.*;
1679+
record R() implements java.io.Serializable {}
1680+
"""
1681+
);
1682+
removeLastCompileOptions(2);
1683+
}
1684+
}
16671685
}

0 commit comments

Comments
 (0)