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:
@@ -115,7 +115,7 @@ public class MessageHeaders implements Map<String, Object>, Serializable {
|
||||
@Nullable
|
||||
private static volatile IdGenerator idGenerator;
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private final Map<String, Object> headers;
|
||||
|
||||
|
||||
|
||||
@@ -104,6 +104,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
|
||||
public static final String RECEIPT_ID = "receipt-id";
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private final Map<String, List<String>> headers;
|
||||
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ public class ErrorMessage extends GenericMessage<Throwable> {
|
||||
private static final long serialVersionUID = -5470210965279837728L;
|
||||
|
||||
@Nullable
|
||||
@SuppressWarnings("serial")
|
||||
private final Message<?> originalMessage;
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class GenericMessage<T> implements Message<T>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4268801052358035098L;
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private final T payload;
|
||||
|
||||
private final MessageHeaders headers;
|
||||
|
||||
@@ -22,6 +22,7 @@ package org.springframework.messaging.protobuf;
|
||||
/**
|
||||
* Protobuf type {@code Msg}
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class Msg extends
|
||||
com.google.protobuf.GeneratedMessage
|
||||
implements MsgOrBuilder {
|
||||
|
||||
@@ -6,6 +6,7 @@ package org.springframework.messaging.protobuf;
|
||||
/**
|
||||
* Protobuf type {@code SecondMsg}
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class SecondMsg extends
|
||||
com.google.protobuf.GeneratedMessage
|
||||
implements SecondMsgOrBuilder {
|
||||
|
||||
Reference in New Issue
Block a user