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

Fix Java Serialization warnings for Tuple #2870

Conversation

KrnSaurabh
Copy link
Contributor

Fix Java Serialization warnings for Tuple.
Maven build throws warnings related to Java Serialization when built with JDK21

non-transient instance field of a serializable class declared with a non-serializable type

#2811

@KrnSaurabh
Copy link
Contributor Author

@pivovarit There are total 73 warnings related to Java Serialization when built on JDK21 and many of them requires to mark the instance variable as transient which additionally requires us to implement readObject()/writeObject() methods in order to serialize/deserialize objects.

In this PR I have fixed issues related to tuples only and there are many more. Hence fixing all 73 issues in one single PR will cause too many lines of code changes and will be hard to review as well.

Hence I am planning to publish fixes for all 73 issues in multiple PRs. Let me know if you have better suggestion on this.

Copy link

codecov bot commented Sep 30, 2024

Codecov Report

Attention: Patch coverage is 17.30769% with 86 lines in your changes missing coverage. Please review.

Project coverage is 92.14%. Comparing base (e43e44b) to head (86b40d8).
Report is 66 commits behind head on master.

Files with missing lines Patch % Lines
src-gen/main/java/io/vavr/Tuple8.java 0.00% 20 Missing ⚠️
src-gen/main/java/io/vavr/Tuple7.java 0.00% 18 Missing ⚠️
src-gen/main/java/io/vavr/Tuple6.java 0.00% 16 Missing ⚠️
src-gen/main/java/io/vavr/Tuple5.java 0.00% 14 Missing ⚠️
src-gen/main/java/io/vavr/Tuple4.java 0.00% 12 Missing ⚠️
src-gen/main/java/io/vavr/Tuple1.java 0.00% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2870      +/-   ##
============================================
- Coverage     92.74%   92.14%   -0.61%     
- Complexity     5247     5266      +19     
============================================
  Files            89       89              
  Lines         12538    12649     +111     
  Branches       1604     1596       -8     
============================================
+ Hits          11628    11655      +27     
- Misses          721      808      +87     
+ Partials        189      186       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pivovarit
Copy link
Member

pivovarit commented Sep 30, 2024

@KrnSaurabh thanks for the hard work - however, I think this needs a different approach. The approach with changing final fields to transient and writing custom serialization/deserialization logic solves the problem by moving it somewhere else - the code won't work if some of those fields are not serializable. This also impacts the immutability of tuples

In this case, it's probably enough to just ignore those serialization issues. This is also what JDK does in AbstractMap.SimpleEntry:

public static class SimpleEntry<K,V> implements Entry<K,V>, java.io.Serializable {
    // ...
    @SuppressWarnings("serial") // Conditionally serializable
    private final K key;
    @SuppressWarnings("serial") // Conditionally serializable
    private V value;
    // ...

not sure about other cases, but serializability of a tuple depends on its elements and there's nothing smart we can about that

@KrnSaurabh
Copy link
Contributor Author

Sure, make sense. Let me try to change the code and suppress the warning.

@KrnSaurabh KrnSaurabh closed this Oct 4, 2024
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

Successfully merging this pull request may close these issues.

2 participants