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

[version/0.x branch] Fix remaining Java Serialization issues with JDK21 #2880

Merged
merged 1 commit into from
Oct 4, 2024
Merged
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
18 changes: 14 additions & 4 deletions vavr/generator/Generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ def generateMainClasses(): Unit = {
private static final long serialVersionUID = 1L;

private final Pattern0<T> pattern;
private final $FunctionType<? super T, ? extends R> f;
private transient final $FunctionType<? super T, ? extends R> f;

private Case0(Pattern0<T> pattern, $FunctionType<? super T, ? extends R> f) {
this.pattern = pattern;
Expand All @@ -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<T, $generics, R> implements Case<T, R> {

private static final long serialVersionUID = 1L;

private final Pattern$i<T, $generics> pattern;
private final $functionType<$argTypes, ? extends R> f;
private $accessModifier $functionType<$argTypes, ? extends R> f;

private Case$i(Pattern$i<T, $generics> pattern, $functionType<$argTypes, ? extends R> f) {
this.pattern = pattern;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -2415,7 +2422,10 @@ def generateMainClasses(): Unit = {
*
* @author Pap Lőrinc
*/
interface ArrayType<T> {
interface ArrayType<T> extends Serializable {

long serialVersionUID = 1L;

@SuppressWarnings("unchecked")
static <T> ArrayType<T> obj() { return (ArrayType<T>) ObjectArrayType.INSTANCE; }

Expand Down
2 changes: 1 addition & 1 deletion vavr/src-gen/main/java/io/vavr/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -5654,4 +5654,4 @@ public boolean isDefinedAt(T obj) {
}
}
}
}
}
5 changes: 4 additions & 1 deletion vavr/src-gen/main/java/io/vavr/Tuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -33,7 +34,9 @@
*
* @author Daniel Dietrich
*/
public interface Tuple {
public interface Tuple extends Serializable {

long serialVersionUID = 1L;

/**
* The maximum arity of an Tuple.
Expand Down
5 changes: 4 additions & 1 deletion vavr/src-gen/main/java/io/vavr/collection/ArrayType.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
*
* @author Pap Lőrinc
*/
interface ArrayType<T> {
interface ArrayType<T> extends Serializable {

long serialVersionUID = 1L;

@SuppressWarnings("unchecked")
static <T> ArrayType<T> obj() { return (ArrayType<T>) ObjectArrayType.INSTANCE; }

Expand Down
1 change: 1 addition & 0 deletions vavr/src/main/java/io/vavr/collection/Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public final class Array<T> implements IndexedSeq<T>, Serializable {

private static final Array<?> EMPTY = new Array<>(new Object[0]);

@SuppressWarnings("serial") // Conditionally serializable
private final Object[] delegate;

private Array(Object[] delegate) {
Expand Down
1 change: 1 addition & 0 deletions vavr/src/main/java/io/vavr/collection/BitMappedTrie.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ final class BitMappedTrie<T> implements Serializable {
static <T> BitMappedTrie<T> empty() { return (BitMappedTrie<T>) EMPTY; }

final ArrayType<T> type;
@SuppressWarnings("serial") // Conditionally serializable
private final Object array;
private final int offset, length;
private final int depthShift;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ final class LeafSingleton<K, V> extends LeafNode<K, V> 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) {
Expand Down Expand Up @@ -446,7 +448,9 @@ final class LeafList<K, V> extends LeafNode<K, V> 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<K, V> tail;
Expand Down Expand Up @@ -592,6 +596,7 @@ final class IndexedNode<K, V> extends AbstractNode<K, V> 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) {
Expand Down Expand Up @@ -705,6 +710,7 @@ final class ArrayNode<K, V> extends AbstractNode<K, V> implements Serializable {

private static final long serialVersionUID = 1L;

@SuppressWarnings("serial") // Conditionally serializable
private final Object[] subNodes;
private final int count;
private final int size;
Expand Down
6 changes: 5 additions & 1 deletion vavr/src/main/java/io/vavr/collection/RedBlackTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
* @param <T> Component type
* @author Daniel Dietrich
*/
interface RedBlackTree<T> extends Iterable<T> {
interface RedBlackTree<T> extends Iterable<T>, Serializable {

long serialVersionUID = 1L;

static <T> RedBlackTree<T> empty(Comparator<? super T> comparator) {
Objects.requireNonNull(comparator, "comparator is null");
Expand Down Expand Up @@ -344,6 +346,7 @@ final class Node<T> implements RedBlackTree<T>, Serializable {
final Color color;
final int blackHeight;
final RedBlackTree<T> left;
@SuppressWarnings("serial")
final T value;
final RedBlackTree<T> right;
final Empty<T> empty;
Expand Down Expand Up @@ -821,6 +824,7 @@ final class Empty<T> implements RedBlackTree<T>, Serializable {

private static final long serialVersionUID = 1L;

@SuppressWarnings("serial") // Conditionally serializable
final Comparator<T> comparator;

// This is no public API! The RedBlackTree takes care of passing the correct Comparator.
Expand Down
1 change: 1 addition & 0 deletions vavr/src/main/java/io/vavr/collection/Tree.java
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ final class Node<T> implements Tree<T>, Serializable {

private static final long serialVersionUID = 1L;

@SuppressWarnings("serial") // Conditionally serializable
private final T value;
private final io.vavr.collection.List<Node<T>> children;

Expand Down
1 change: 1 addition & 0 deletions vavr/src/main/java/io/vavr/collection/TreeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,7 @@ final class Specific<K, V> implements EntryComparator<K, V> {

private static final long serialVersionUID = 1L;

@SuppressWarnings("serial") // Conditionally serializable
private final Comparator<K> keyComparator;

@SuppressWarnings("unchecked")
Expand Down
2 changes: 2 additions & 0 deletions vavr/src/test/java/io/vavr/collection/BitSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ private static final class Mapper<T> implements Serializable {

private static final long serialVersionUID = 1L;

@SuppressWarnings("serial") // Conditionally serializable
private final java.util.Map<Integer, T> fromIntMap = new java.util.HashMap<>();
@SuppressWarnings("serial") // Conditionally serializable
private final java.util.Map<T, Integer> toIntMap = new java.util.HashMap<>();
private int nextValue = 0;

Expand Down
Loading