Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
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
  • Loading branch information
3 people committed Sep 28, 2020
1 parent d25b03e commit ac15d6445b9241c2955349fd4b573aa84b82d13f
Showing with 22 additions and 4 deletions.
  1. +2 −2 src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
  2. +20 −2 test/langtools/tools/javac/records/RecordCompilationTests.java
@@ -5348,8 +5348,8 @@ private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c) {
}

if (svuid == null) {
log.warning(LintCategory.SERIAL,
tree.pos(), Warnings.MissingSVUID(c));
if (!c.isRecord())
log.warning(LintCategory.SERIAL, tree.pos(), Warnings.MissingSVUID(c));
return;
}

@@ -26,7 +26,7 @@
/**
* RecordCompilationTests
*
* @test 8250629 8252307 8247352
* @test 8250629 8252307 8247352 8241151
* @summary Negative compilation tests, and positive compilation (smoke) tests for records
* @library /lib/combo /tools/lib /tools/javac/lib
* @modules
@@ -145,8 +145,10 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
}
}

boolean useAP;

public RecordCompilationTests() {
boolean useAP = System.getProperty("useAP") == null ? false : System.getProperty("useAP").equals("true");
useAP = System.getProperty("useAP", "false").equals("true");
setDefaultFilename("R.java");
setCompileOptions(useAP ? PREVIEW_OPTIONS_WITH_AP : PREVIEW_OPTIONS);
System.out.println(useAP ? "running all tests using an annotation processor" : "running all tests without annotation processor");
@@ -1664,4 +1666,20 @@ record R(String s[]) {}
"""
);
}

public void testNoWarningForSerializableRecords() {
if (!useAP) {
/* dont execute this test when the default annotation processor is on as it will fail due to
* spurious warnings
*/
appendCompileOptions("-Werror", "-Xlint:serial");
assertOK(
"""
import java.io.*;
record R() implements java.io.Serializable {}
"""
);
removeLastCompileOptions(2);
}
}
}

0 comments on commit ac15d64

Please sign in to comment.