RFR: 8231622: SuppressWarning("serial") ignored on field serialVersionUID [v3]
Jonathan Gibbons
jjg at openjdk.java.net
Tue Dec 8 17:36:16 UTC 2020
On Tue, 8 Dec 2020 13:02:33 GMT, Guoxiong Li <github.com+13688759+lgxbslgx at openjdk.org> wrote:
>> Hi all,
>>
>> Currently, a warning is generated when compiling the following code by using the option `-Xlint`.
>>
>> import java.io.Serializable;
>> class B implements Serializable {
>> @SuppressWarnings("serial")
>> private static final byte serialVersionUID = 5;
>> }
>>
>> output:
>> B.java:4: warning: [serial] serialVersionUID must be of type long in class B
>> private static final byte serialVersionUID = 5;
>> ^
>> 1 warning
>>
>> The annotation `@SuppressWarnings("serial")` on field serialVersionUID is ignored by the compiler.
>> This patch fixes it and adds some tests.
>> Thank you for taking the time to review.
>>
>> Best Regards.
>
> Guoxiong Li has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains four additional commits since the last revision:
>
> - Revise tests by using library toolbox.
> - Merge remote-tracking branch 'origin' into JDK-8231622
> - Revise test cases. Remove legal header and add /nodynamiccopyright/
> - 8231622: SuppressWarning(serial) ignored on field serialVersionUID
Nice improvement. You can make it even better in 3 places by using `ToolBox.checkEquals`, which provides more detailed reporting in the case of a difference being found.
test/langtools/tools/javac/T8231622/T8231622.java line 79:
> 77: if (!Objects.equals(output, expected)) {
> 78: throw new AssertionError("incorrect output\nactual=" + output + "\nexpected=" + expected);
> 79: }
ToolBox provides `checkEquals` which provides a more detailed error message in the case of a difference.
-------------
PR: https://git.openjdk.java.net/jdk/pull/1626
More information about the compiler-dev
mailing list