RFR: 8231622: SuppressWarning("serial") ignored on field serialVersionUID [v2]

Jonathan Gibbons jjg at openjdk.java.net
Mon Dec 7 19:24:14 UTC 2020

On Fri, 4 Dec 2020 18:26:36 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 incrementally with one additional commit since the last revision:
>   Revise test cases. Remove legal header and add /nodynamiccopyright/

I approve these changes.

That being said, a more modern idiom for negative tests involving small source files and corresponding small golden files, is to write a single file that uses library code like `toolbox.ToolBox` to write files on the fly, perhaps from content in a text block, and to compare the output against another text block.  For slightly more advanced usage, you can compile strings directly using API like `SimpleJavaFileObject`, and avoid the file system altogether.


Marked as reviewed by jjg (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/1626

More information about the compiler-dev mailing list