Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 ac15d64
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Expand Up @@ -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;
}

Expand Down
22 changes: 20 additions & 2 deletions test/langtools/tools/javac/records/RecordCompilationTests.java
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -1664,4 +1666,20 @@ record R<T>(T t[]) {}
"""
);
}

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

1 comment on commit ac15d64

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on ac15d64 Sep 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.