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:
@@ -72,12 +72,14 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
|
||||
|
||||
/** Package-protected to allow direct access for efficiency. */
|
||||
@SuppressWarnings("serial")
|
||||
TargetSource targetSource = EMPTY_TARGET_SOURCE;
|
||||
|
||||
/** Whether the Advisors are already filtered for the specific target class. */
|
||||
private boolean preFiltered = false;
|
||||
|
||||
/** The AdvisorChainFactory to use. */
|
||||
@SuppressWarnings("serial")
|
||||
AdvisorChainFactory advisorChainFactory = new DefaultAdvisorChainFactory();
|
||||
|
||||
/** Cache with Method as key and advisor chain List as value. */
|
||||
@@ -87,12 +89,14 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
* Interfaces to be implemented by the proxy. Held in List to keep the order
|
||||
* of registration, to create JDK proxy with specified order of interfaces.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
private List<Class<?>> interfaces = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* List of Advisors. If an Advice is added, it will be wrapped
|
||||
* in an Advisor before being added to this List.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
private List<Advisor> advisors = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
@@ -46,8 +46,10 @@ public class ComposablePointcut implements Pointcut, Serializable {
|
||||
/** use serialVersionUID from Spring 1.2 for interoperability. */
|
||||
private static final long serialVersionUID = -2743223737633663832L;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private ClassFilter classFilter;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private MethodMatcher methodMatcher;
|
||||
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSour
|
||||
|
||||
|
||||
/** Logger available to subclasses. */
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
protected final transient Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
/** Name of the target bean we will create on each invocation. */
|
||||
private String targetBeanName;
|
||||
@@ -66,6 +66,7 @@ public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSour
|
||||
* BeanFactory that owns this TargetSource. We need to hold onto this
|
||||
* reference so that we can create new prototype instances as necessary.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ public class HotSwappableTargetSource implements TargetSource, Serializable {
|
||||
|
||||
|
||||
/** The current target object. */
|
||||
@SuppressWarnings("serial")
|
||||
private Object target;
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ public class SingletonTargetSource implements TargetSource, Serializable {
|
||||
|
||||
|
||||
/** Target cached and invoked using reflection. */
|
||||
@SuppressWarnings("serial")
|
||||
private final Object target;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user