Fix serialization compiler warnings with Java 18
As of Java 18, the serial lint warning in javac has been expanded to check for class fields that are not marked as `Serializable`. See https://www.oracle.com/java/technologies/javase/18all-relnotes.html#JDK-8202056 In the Spring Framework codebase, this can happen with `Map`, `Set` or `List` attributes which are often assigned with an unmodifiable implementation variant. Such implementations are `Serializable` but cannot be used as field types. This commit ensures that the following changes are applied: * fields are marked as transient if they can't be serialized * classes are marked as `Serializable` if this was missing * `@SuppressWarnings("serial")` is applied where relevant
This commit is contained in:
@@ -102,6 +102,7 @@ public class MimeType implements Comparable<MimeType>, Serializable {
|
||||
|
||||
private final String subtype;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private final Map<String, String> parameters;
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -47,7 +47,7 @@ final class UnmodifiableMultiValueMap<K,V> implements MultiValueMap<K,V>, Serial
|
||||
|
||||
private static final long serialVersionUID = -8697084563854098920L;
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private final MultiValueMap<K, V> delegate;
|
||||
|
||||
@Nullable
|
||||
@@ -266,7 +266,7 @@ final class UnmodifiableMultiValueMap<K,V> implements MultiValueMap<K,V>, Serial
|
||||
|
||||
private static final long serialVersionUID = 2407578793783925203L;
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private final Set<Entry<K, List<V>>> delegate;
|
||||
|
||||
|
||||
@@ -531,6 +531,7 @@ final class UnmodifiableMultiValueMap<K,V> implements MultiValueMap<K,V>, Serial
|
||||
|
||||
private static final long serialVersionUID = 5518377583904339588L;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private final Collection<List<V>> delegate;
|
||||
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ class SerializationConverterTests {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@SuppressWarnings({"unused", "serial"})
|
||||
private Object object;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user