From f77636cc61870fc864691b5f9263b6879c62e2c4 Mon Sep 17 00:00:00 2001 From: karnsa Date: Tue, 1 Oct 2024 01:43:41 +0530 Subject: [PATCH] Fix Java Serialization warnings for Tuple --- vavr/generator/Generator.scala | 20 ++++++++++- vavr/src-gen/main/java/io/vavr/Tuple1.java | 14 +++++++- vavr/src-gen/main/java/io/vavr/Tuple2.java | 18 ++++++++-- vavr/src-gen/main/java/io/vavr/Tuple3.java | 22 ++++++++++-- vavr/src-gen/main/java/io/vavr/Tuple4.java | 26 +++++++++++--- vavr/src-gen/main/java/io/vavr/Tuple5.java | 30 +++++++++++++--- vavr/src-gen/main/java/io/vavr/Tuple6.java | 34 ++++++++++++++---- vavr/src-gen/main/java/io/vavr/Tuple7.java | 38 ++++++++++++++++---- vavr/src-gen/main/java/io/vavr/Tuple8.java | 42 +++++++++++++++++----- 9 files changed, 207 insertions(+), 37 deletions(-) diff --git a/vavr/generator/Generator.scala b/vavr/generator/Generator.scala index e0468c23d..a46fcc043 100644 --- a/vavr/generator/Generator.scala +++ b/vavr/generator/Generator.scala @@ -1953,7 +1953,7 @@ def generateMainClasses(): Unit = { /$javadoc * The ${j.ordinal} element of this tuple. */ - public final T$j _$j; + transient public T$j _$j; """)("\n\n")} ${if (i == 0) xs""" @@ -2211,6 +2211,24 @@ def generateMainClasses(): Unit = { return ${if (i == 0) "1" else s"""Tuple.hash(${(1 to i).gen(j => s"_$j")(", ")})"""}; } + ${(i > 0).gen(xs""" + private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + s.defaultWriteObject(); + ${(1 to i).gen(j => xs""" + s.writeObject(_$j); + """)("\n")} + } + + @SuppressWarnings("unchecked") + private void readObject(java.io.ObjectInputStream s) + throws java.io.IOException, ClassNotFoundException { + s.defaultReadObject(); + ${(1 to i).gen(j => xs""" + _$j = (T$j) s.readObject(); + """)("\n")} + } + """)} + @Override public String toString() { return ${if (i == 0) "\"()\"" else s""""(" + ${(1 to i).gen(j => s"_$j")(" + \", \" + ")} + ")""""}; diff --git a/vavr/src-gen/main/java/io/vavr/Tuple1.java b/vavr/src-gen/main/java/io/vavr/Tuple1.java index 143d3e20e..fba0af1f3 100644 --- a/vavr/src-gen/main/java/io/vavr/Tuple1.java +++ b/vavr/src-gen/main/java/io/vavr/Tuple1.java @@ -43,7 +43,7 @@ public final class Tuple1 implements Tuple, Comparable>, Serializ /** * The 1st element of this tuple. */ - public final T1 _1; + transient public T1 _1; /** * Constructs a tuple of one element. @@ -282,6 +282,18 @@ public int hashCode() { return Tuple.hash(_1); } + private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + s.defaultWriteObject(); + s.writeObject(_1); + } + + @SuppressWarnings("unchecked") + private void readObject(java.io.ObjectInputStream s) + throws java.io.IOException, ClassNotFoundException { + s.defaultReadObject(); + _1 = (T1) s.readObject(); + } + @Override public String toString() { return "(" + _1 + ")"; diff --git a/vavr/src-gen/main/java/io/vavr/Tuple2.java b/vavr/src-gen/main/java/io/vavr/Tuple2.java index 8cf9aeb97..edf3623e9 100644 --- a/vavr/src-gen/main/java/io/vavr/Tuple2.java +++ b/vavr/src-gen/main/java/io/vavr/Tuple2.java @@ -47,12 +47,12 @@ public final class Tuple2 implements Tuple, Comparable>, /** * The 1st element of this tuple. */ - public final T1 _1; + transient public T1 _1; /** * The 2nd element of this tuple. */ - public final T2 _2; + transient public T2 _2; /** * Constructs a tuple of two elements. @@ -367,6 +367,20 @@ public int hashCode() { return Tuple.hash(_1, _2); } + private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + s.defaultWriteObject(); + s.writeObject(_1); + s.writeObject(_2); + } + + @SuppressWarnings("unchecked") + private void readObject(java.io.ObjectInputStream s) + throws java.io.IOException, ClassNotFoundException { + s.defaultReadObject(); + _1 = (T1) s.readObject(); + _2 = (T2) s.readObject(); + } + @Override public String toString() { return "(" + _1 + ", " + _2 + ")"; diff --git a/vavr/src-gen/main/java/io/vavr/Tuple3.java b/vavr/src-gen/main/java/io/vavr/Tuple3.java index c98dd5e65..bd6bb06c6 100644 --- a/vavr/src-gen/main/java/io/vavr/Tuple3.java +++ b/vavr/src-gen/main/java/io/vavr/Tuple3.java @@ -45,17 +45,17 @@ public final class Tuple3 implements Tuple, Comparable implements Tuple, Comparable implements Tuple, Comparable implements Tuple, Comparable implements Tuple, Comparab /** * The 1st element of this tuple. */ - public final T1 _1; + transient public T1 _1; /** * The 2nd element of this tuple. */ - public final T2 _2; + transient public T2 _2; /** * The 3rd element of this tuple. */ - public final T3 _3; + transient public T3 _3; /** * The 4th element of this tuple. */ - public final T4 _4; + transient public T4 _4; /** * The 5th element of this tuple. */ - public final T5 _5; + transient public T5 _5; /** * The 6th element of this tuple. */ - public final T6 _6; + transient public T6 _6; /** * The 7th element of this tuple. */ - public final T7 _7; + transient public T7 _7; /** * Constructs a tuple of 7 elements. @@ -539,6 +539,30 @@ public int hashCode() { return Tuple.hash(_1, _2, _3, _4, _5, _6, _7); } + private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + s.defaultWriteObject(); + s.writeObject(_1); + s.writeObject(_2); + s.writeObject(_3); + s.writeObject(_4); + s.writeObject(_5); + s.writeObject(_6); + s.writeObject(_7); + } + + @SuppressWarnings("unchecked") + private void readObject(java.io.ObjectInputStream s) + throws java.io.IOException, ClassNotFoundException { + s.defaultReadObject(); + _1 = (T1) s.readObject(); + _2 = (T2) s.readObject(); + _3 = (T3) s.readObject(); + _4 = (T4) s.readObject(); + _5 = (T5) s.readObject(); + _6 = (T6) s.readObject(); + _7 = (T7) s.readObject(); + } + @Override public String toString() { return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ")"; diff --git a/vavr/src-gen/main/java/io/vavr/Tuple8.java b/vavr/src-gen/main/java/io/vavr/Tuple8.java index 86df52849..3096a55cb 100644 --- a/vavr/src-gen/main/java/io/vavr/Tuple8.java +++ b/vavr/src-gen/main/java/io/vavr/Tuple8.java @@ -50,42 +50,42 @@ public final class Tuple8 implements Tuple, Comp /** * The 1st element of this tuple. */ - public final T1 _1; + transient public T1 _1; /** * The 2nd element of this tuple. */ - public final T2 _2; + transient public T2 _2; /** * The 3rd element of this tuple. */ - public final T3 _3; + transient public T3 _3; /** * The 4th element of this tuple. */ - public final T4 _4; + transient public T4 _4; /** * The 5th element of this tuple. */ - public final T5 _5; + transient public T5 _5; /** * The 6th element of this tuple. */ - public final T6 _6; + transient public T6 _6; /** * The 7th element of this tuple. */ - public final T7 _7; + transient public T7 _7; /** * The 8th element of this tuple. */ - public final T8 _8; + transient public T8 _8; /** * Constructs a tuple of 8 elements. @@ -570,6 +570,32 @@ public int hashCode() { return Tuple.hash(_1, _2, _3, _4, _5, _6, _7, _8); } + private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + s.defaultWriteObject(); + s.writeObject(_1); + s.writeObject(_2); + s.writeObject(_3); + s.writeObject(_4); + s.writeObject(_5); + s.writeObject(_6); + s.writeObject(_7); + s.writeObject(_8); + } + + @SuppressWarnings("unchecked") + private void readObject(java.io.ObjectInputStream s) + throws java.io.IOException, ClassNotFoundException { + s.defaultReadObject(); + _1 = (T1) s.readObject(); + _2 = (T2) s.readObject(); + _3 = (T3) s.readObject(); + _4 = (T4) s.readObject(); + _5 = (T5) s.readObject(); + _6 = (T6) s.readObject(); + _7 = (T7) s.readObject(); + _8 = (T8) s.readObject(); + } + @Override public String toString() { return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ")";