From 6bc40eb47a59711b9a5af1ff8e95f7a291231cbf Mon Sep 17 00:00:00 2001 From: karnsa Date: Fri, 4 Oct 2024 13:44:09 +0530 Subject: [PATCH] fix-serializable-issues JDK21 --- vavr/generator/Generator.scala | 15 +++++++++++---- vavr/src-gen/main/java/io/vavr/API.java | 2 +- vavr/src-gen/main/java/io/vavr/Tuple.java | 5 ++++- .../main/java/io/vavr/collection/ArrayType.java | 2 +- vavr/src/main/java/io/vavr/collection/Array.java | 1 + .../java/io/vavr/collection/BitMappedTrie.java | 1 + .../io/vavr/collection/HashArrayMappedTrie.java | 6 ++++++ .../java/io/vavr/collection/RedBlackTree.java | 6 +++++- vavr/src/main/java/io/vavr/collection/Tree.java | 1 + .../src/main/java/io/vavr/collection/TreeMap.java | 1 + .../test/java/io/vavr/collection/BitSetTest.java | 2 ++ 11 files changed, 34 insertions(+), 8 deletions(-) diff --git a/vavr/generator/Generator.scala b/vavr/generator/Generator.scala index ea62db987..82f82697a 100644 --- a/vavr/generator/Generator.scala +++ b/vavr/generator/Generator.scala @@ -1104,7 +1104,7 @@ def generateMainClasses(): Unit = { private static final long serialVersionUID = 1L; private final Pattern0 pattern; - private final $FunctionType f; + private transient final $FunctionType f; private Case0(Pattern0 pattern, $FunctionType f) { this.pattern = pattern; @@ -1130,13 +1130,18 @@ def generateMainClasses(): Unit = { case 2 => BiFunctionType case _ => s"Function$i" } + val accessModifier = i match { + case 1 => "transient final" + case 2 => "transient final" + case _ => "final" + } xs""" public static final class Case$i implements Case { private static final long serialVersionUID = 1L; private final Pattern$i pattern; - private final $functionType<$argTypes, ? extends R> f; + private $accessModifier $functionType<$argTypes, ? extends R> f; private Case$i(Pattern$i pattern, $functionType<$argTypes, ? extends R> f) { this.pattern = pattern; @@ -2329,7 +2334,9 @@ def generateMainClasses(): Unit = { * * @author Daniel Dietrich */ - public interface Tuple { + public interface Tuple extends ${im.getType("java.io.Serializable")} { + + long serialVersionUID = 1L; /** * The maximum arity of an Tuple. @@ -2415,7 +2422,7 @@ def generateMainClasses(): Unit = { * * @author Pap Lőrinc */ - interface ArrayType { + interface ArrayType extends Serializable { @SuppressWarnings("unchecked") static ArrayType obj() { return (ArrayType) ObjectArrayType.INSTANCE; } diff --git a/vavr/src-gen/main/java/io/vavr/API.java b/vavr/src-gen/main/java/io/vavr/API.java index 8afdc2c16..43038581e 100644 --- a/vavr/src-gen/main/java/io/vavr/API.java +++ b/vavr/src-gen/main/java/io/vavr/API.java @@ -5654,4 +5654,4 @@ public boolean isDefinedAt(T obj) { } } } -} +} \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/Tuple.java b/vavr/src-gen/main/java/io/vavr/Tuple.java index 0010f0ef4..ad63c3e20 100644 --- a/vavr/src-gen/main/java/io/vavr/Tuple.java +++ b/vavr/src-gen/main/java/io/vavr/Tuple.java @@ -25,6 +25,7 @@ import io.vavr.collection.Seq; import io.vavr.collection.Stream; +import java.io.Serializable; import java.util.Map; import java.util.Objects; @@ -33,7 +34,9 @@ * * @author Daniel Dietrich */ -public interface Tuple { +public interface Tuple extends Serializable { + + long serialVersionUID = 1L; /** * The maximum arity of an Tuple. diff --git a/vavr/src-gen/main/java/io/vavr/collection/ArrayType.java b/vavr/src-gen/main/java/io/vavr/collection/ArrayType.java index dac013233..8316c2dec 100644 --- a/vavr/src-gen/main/java/io/vavr/collection/ArrayType.java +++ b/vavr/src-gen/main/java/io/vavr/collection/ArrayType.java @@ -32,7 +32,7 @@ * * @author Pap Lőrinc */ -interface ArrayType { +interface ArrayType extends Serializable { @SuppressWarnings("unchecked") static ArrayType obj() { return (ArrayType) ObjectArrayType.INSTANCE; } diff --git a/vavr/src/main/java/io/vavr/collection/Array.java b/vavr/src/main/java/io/vavr/collection/Array.java index fe68ec2dd..7b0e0cca9 100644 --- a/vavr/src/main/java/io/vavr/collection/Array.java +++ b/vavr/src/main/java/io/vavr/collection/Array.java @@ -45,6 +45,7 @@ public final class Array implements IndexedSeq, Serializable { private static final Array EMPTY = new Array<>(new Object[0]); + @SuppressWarnings("serial") // Conditionally serializable private final Object[] delegate; private Array(Object[] delegate) { diff --git a/vavr/src/main/java/io/vavr/collection/BitMappedTrie.java b/vavr/src/main/java/io/vavr/collection/BitMappedTrie.java index e2e751a96..964cc1b64 100644 --- a/vavr/src/main/java/io/vavr/collection/BitMappedTrie.java +++ b/vavr/src/main/java/io/vavr/collection/BitMappedTrie.java @@ -60,6 +60,7 @@ final class BitMappedTrie implements Serializable { static BitMappedTrie empty() { return (BitMappedTrie) EMPTY; } final ArrayType type; + @SuppressWarnings("serial") // Conditionally serializable private final Object array; private final int offset, length; private final int depthShift; diff --git a/vavr/src/main/java/io/vavr/collection/HashArrayMappedTrie.java b/vavr/src/main/java/io/vavr/collection/HashArrayMappedTrie.java index cbe9a765c..9d616f25d 100644 --- a/vavr/src/main/java/io/vavr/collection/HashArrayMappedTrie.java +++ b/vavr/src/main/java/io/vavr/collection/HashArrayMappedTrie.java @@ -377,7 +377,9 @@ final class LeafSingleton extends LeafNode implements Serializable { private static final long serialVersionUID = 1L; private final int hash; + @SuppressWarnings("serial") // Conditionally serializable private final K key; + @SuppressWarnings("serial") // Conditionally serializable private final V value; LeafSingleton(int hash, K key, V value) { @@ -446,7 +448,9 @@ final class LeafList extends LeafNode implements Serializable { private static final long serialVersionUID = 1L; private final int hash; + @SuppressWarnings("serial") // Conditionally serializable private final K key; + @SuppressWarnings("serial") // Conditionally serializable private final V value; private final int size; private final LeafNode tail; @@ -592,6 +596,7 @@ final class IndexedNode extends AbstractNode implements Serializable private final int bitmap; private final int size; + @SuppressWarnings("serial") // Conditionally serializable private final Object[] subNodes; IndexedNode(int bitmap, int size, Object[] subNodes) { @@ -705,6 +710,7 @@ final class ArrayNode extends AbstractNode implements Serializable { private static final long serialVersionUID = 1L; + @SuppressWarnings("serial") // Conditionally serializable private final Object[] subNodes; private final int count; private final int size; diff --git a/vavr/src/main/java/io/vavr/collection/RedBlackTree.java b/vavr/src/main/java/io/vavr/collection/RedBlackTree.java index 69274fa50..86679d4bd 100644 --- a/vavr/src/main/java/io/vavr/collection/RedBlackTree.java +++ b/vavr/src/main/java/io/vavr/collection/RedBlackTree.java @@ -46,7 +46,9 @@ * @param Component type * @author Daniel Dietrich */ -interface RedBlackTree extends Iterable { +interface RedBlackTree extends Iterable, Serializable { + + long serialVersionUID = 1L; static RedBlackTree empty(Comparator comparator) { Objects.requireNonNull(comparator, "comparator is null"); @@ -344,6 +346,7 @@ final class Node implements RedBlackTree, Serializable { final Color color; final int blackHeight; final RedBlackTree left; + @SuppressWarnings("serial") final T value; final RedBlackTree right; final Empty empty; @@ -821,6 +824,7 @@ final class Empty implements RedBlackTree, Serializable { private static final long serialVersionUID = 1L; + @SuppressWarnings("serial") // Conditionally serializable final Comparator comparator; // This is no public API! The RedBlackTree takes care of passing the correct Comparator. diff --git a/vavr/src/main/java/io/vavr/collection/Tree.java b/vavr/src/main/java/io/vavr/collection/Tree.java index fd402017c..906260b74 100644 --- a/vavr/src/main/java/io/vavr/collection/Tree.java +++ b/vavr/src/main/java/io/vavr/collection/Tree.java @@ -866,6 +866,7 @@ final class Node implements Tree, Serializable { private static final long serialVersionUID = 1L; + @SuppressWarnings("serial") // Conditionally serializable private final T value; private final io.vavr.collection.List> children; diff --git a/vavr/src/main/java/io/vavr/collection/TreeMap.java b/vavr/src/main/java/io/vavr/collection/TreeMap.java index 48d92cb01..8e10f2453 100644 --- a/vavr/src/main/java/io/vavr/collection/TreeMap.java +++ b/vavr/src/main/java/io/vavr/collection/TreeMap.java @@ -1562,6 +1562,7 @@ final class Specific implements EntryComparator { private static final long serialVersionUID = 1L; + @SuppressWarnings("serial") // Conditionally serializable private final Comparator keyComparator; @SuppressWarnings("unchecked") diff --git a/vavr/src/test/java/io/vavr/collection/BitSetTest.java b/vavr/src/test/java/io/vavr/collection/BitSetTest.java index fde3fb1b7..14042e82c 100644 --- a/vavr/src/test/java/io/vavr/collection/BitSetTest.java +++ b/vavr/src/test/java/io/vavr/collection/BitSetTest.java @@ -572,7 +572,9 @@ private static final class Mapper implements Serializable { private static final long serialVersionUID = 1L; + @SuppressWarnings("serial") // Conditionally serializable private final java.util.Map fromIntMap = new java.util.HashMap<>(); + @SuppressWarnings("serial") // Conditionally serializable private final java.util.Map toIntMap = new java.util.HashMap<>(); private int nextValue = 0;