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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion generator/Generator.sc
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,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"""
Expand Down Expand Up @@ -2238,6 +2238,24 @@ def generateMainClasses(): Unit = {
return ${if (i == 0) "1" else if (i == 1) "Objects.hashCode(_1)" else if (i == 2) "Objects.hashCode(_1) ^ Objects.hashCode(_2)" else s"""Objects.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")(" + \", \" + ")} + ")""""};
Expand Down
14 changes: 13 additions & 1 deletion src-gen/main/java/io/vavr/Tuple1.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
/**
* The 1st element of this tuple.
*/
public final T1 _1;
transient public T1 _1;

/**
* Constructs a tuple of one element.
Expand Down Expand Up @@ -303,6 +303,18 @@
return Objects.hashCode(_1);
}

private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {
s.defaultWriteObject();
s.writeObject(_1);
}

Check warning on line 309 in src-gen/main/java/io/vavr/Tuple1.java

View check run for this annotation

Codecov / codecov/patch

src-gen/main/java/io/vavr/Tuple1.java#L307-L309

Added lines #L307 - L309 were not covered by tests

@SuppressWarnings("unchecked")
private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException {
s.defaultReadObject();
_1 = (T1) s.readObject();
}

Check warning on line 316 in src-gen/main/java/io/vavr/Tuple1.java

View check run for this annotation

Codecov / codecov/patch

src-gen/main/java/io/vavr/Tuple1.java#L314-L316

Added lines #L314 - L316 were not covered by tests

@Override
public String toString() {
return "(" + _1 + ")";
Expand Down
18 changes: 16 additions & 2 deletions src-gen/main/java/io/vavr/Tuple2.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public final class Tuple2<T1, T2> implements Tuple, Serializable {
/**
* 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.
Expand Down Expand Up @@ -397,6 +397,20 @@ public int hashCode() {
return Objects.hashCode(_1) ^ Objects.hashCode(_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 + ")";
Expand Down
22 changes: 19 additions & 3 deletions src-gen/main/java/io/vavr/Tuple3.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ public final class Tuple3<T1, T2, T3> implements Tuple, Serializable {
/**
* 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;

/**
* Constructs a tuple of three elements.
Expand Down Expand Up @@ -420,6 +420,22 @@ public int hashCode() {
return Objects.hash(_1, _2, _3);
}

private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {
s.defaultWriteObject();
s.writeObject(_1);
s.writeObject(_2);
s.writeObject(_3);
}

@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();
}

@Override
public String toString() {
return "(" + _1 + ", " + _2 + ", " + _3 + ")";
Expand Down
26 changes: 22 additions & 4 deletions src-gen/main/java/io/vavr/Tuple4.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@
/**
* 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;

/**
* Constructs a tuple of 4 elements.
Expand Down Expand Up @@ -467,6 +467,24 @@
return Objects.hash(_1, _2, _3, _4);
}

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);
}

Check warning on line 476 in src-gen/main/java/io/vavr/Tuple4.java

View check run for this annotation

Codecov / codecov/patch

src-gen/main/java/io/vavr/Tuple4.java#L471-L476

Added lines #L471 - L476 were not covered by tests

@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();
}

Check warning on line 486 in src-gen/main/java/io/vavr/Tuple4.java

View check run for this annotation

Codecov / codecov/patch

src-gen/main/java/io/vavr/Tuple4.java#L481-L486

Added lines #L481 - L486 were not covered by tests

@Override
public String toString() {
return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ")";
Expand Down
30 changes: 25 additions & 5 deletions src-gen/main/java/io/vavr/Tuple5.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,27 @@
/**
* 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;

/**
* Constructs a tuple of 5 elements.
Expand Down Expand Up @@ -515,6 +515,26 @@
return Objects.hash(_1, _2, _3, _4, _5);
}

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);
}

Check warning on line 525 in src-gen/main/java/io/vavr/Tuple5.java

View check run for this annotation

Codecov / codecov/patch

src-gen/main/java/io/vavr/Tuple5.java#L519-L525

Added lines #L519 - L525 were not covered by tests

@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();
}

Check warning on line 536 in src-gen/main/java/io/vavr/Tuple5.java

View check run for this annotation

Codecov / codecov/patch

src-gen/main/java/io/vavr/Tuple5.java#L530-L536

Added lines #L530 - L536 were not covered by tests

@Override
public String toString() {
return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ")";
Expand Down
34 changes: 28 additions & 6 deletions src-gen/main/java/io/vavr/Tuple6.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,32 @@
/**
* 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;

/**
* Constructs a tuple of 6 elements.
Expand Down Expand Up @@ -564,6 +564,28 @@
return Objects.hash(_1, _2, _3, _4, _5, _6);
}

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);
}

Check warning on line 575 in src-gen/main/java/io/vavr/Tuple6.java

View check run for this annotation

Codecov / codecov/patch

src-gen/main/java/io/vavr/Tuple6.java#L568-L575

Added lines #L568 - L575 were not covered by tests

@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();
}

Check warning on line 587 in src-gen/main/java/io/vavr/Tuple6.java

View check run for this annotation

Codecov / codecov/patch

src-gen/main/java/io/vavr/Tuple6.java#L580-L587

Added lines #L580 - L587 were not covered by tests

@Override
public String toString() {
return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ")";
Expand Down
38 changes: 31 additions & 7 deletions src-gen/main/java/io/vavr/Tuple7.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,37 +55,37 @@
/**
* 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.
Expand Down Expand Up @@ -614,6 +614,30 @@
return Objects.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);
}

Check warning on line 626 in src-gen/main/java/io/vavr/Tuple7.java

View check run for this annotation

Codecov / codecov/patch

src-gen/main/java/io/vavr/Tuple7.java#L618-L626

Added lines #L618 - L626 were not covered by tests

@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();
}

Check warning on line 639 in src-gen/main/java/io/vavr/Tuple7.java

View check run for this annotation

Codecov / codecov/patch

src-gen/main/java/io/vavr/Tuple7.java#L631-L639

Added lines #L631 - L639 were not covered by tests

@Override
public String toString() {
return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ")";
Expand Down
Loading
Loading