Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SE_NO_SERIALVERSIONID with Serializable records #2793

Closed
rovarga opened this issue Jan 3, 2024 · 3 comments
Closed

SE_NO_SERIALVERSIONID with Serializable records #2793

rovarga opened this issue Jan 3, 2024 · 3 comments
Assignees

Comments

@rovarga
Copy link
Contributor

rovarga commented Jan 3, 2024

Having a Serializable record without a serialVersionUID constant triggers SE_NO_SERIALVERSIONID.

This is essentially a false positive, as records are special to serialization -- SpotBugs should not report this warning for records.

@hazendaz
Copy link
Member

hazendaz commented Jan 4, 2024

I guess in theory true its not an error, but it could be a proper warning. It clearly states in there that sometimes you do need to do so in certain situations or that is how I read it. Maybe it needs its own classification though since it sets to 0L if not listed.

gtoison added a commit to gtoison/spotbugs that referenced this issue Jan 5, 2024
@gtoison
Copy link
Contributor

gtoison commented Jan 5, 2024

My understanding is that serialVersionUID is not considered when loading a record:
the requirement for matching the serialVersionUID value is waived for record classes

There's already a special case to ignore enums, I think it should be the same records

isEnum = "java.lang.Enum".equals(superClassname);
if (isEnum) {
return;
}

It also seems to report SE_NO_SUITABLE_CONSTRUCTOR_FOR_EXTERNALIZATION which is not great because records are not externalizable anyway (so there might be another bug to report: a record should not implement Externalizable)

hazendaz pushed a commit that referenced this issue Jan 6, 2024
* test: reproducer for issue #2793

* fix: ignore records when looking for serialization bugs
gtoison added a commit that referenced this issue Jan 6, 2024
hazendaz pushed a commit that referenced this issue Jan 6, 2024
@hazendaz
Copy link
Member

hazendaz commented Jan 6, 2024

Fixed via #2795

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants