From 738160538eab258deacbacac873e53647fb40abb Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 13 Jun 2017 03:11:36 +0200 Subject: [PATCH] TargetSource.getTarget() is nullable again (for compatibility with MethodInvocation.getThis) Issue: SPR-15651 --- .../AbstractPrototypeBasedTargetSource.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/target/AbstractPrototypeBasedTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/AbstractPrototypeBasedTargetSource.java index 415d0e57e1..4376dcddf6 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/AbstractPrototypeBasedTargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/AbstractPrototypeBasedTargetSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -97,7 +97,7 @@ public abstract class AbstractPrototypeBasedTargetSource extends AbstractBeanFac private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { throw new NotSerializableException("A prototype-based TargetSource itself is not deserializable - " + - "just a disconnected SingletonTargetSource is"); + "just a disconnected SingletonTargetSource or EmptyTargetSource is"); } /** @@ -113,13 +113,15 @@ public abstract class AbstractPrototypeBasedTargetSource extends AbstractBeanFac logger.debug("Disconnecting TargetSource [" + this + "]"); } try { - // Create disconnected SingletonTargetSource. - return new SingletonTargetSource(getTarget()); + // Create disconnected SingletonTargetSource/EmptyTargetSource. + Object target = getTarget(); + return (target != null ? new SingletonTargetSource(target) : + EmptyTargetSource.forClass(getTargetClass())); } catch (Exception ex) { - logger.error("Cannot get target for disconnecting TargetSource [" + this + "]", ex); - throw new NotSerializableException( - "Cannot get target for disconnecting TargetSource [" + this + "]: " + ex); + String msg = "Cannot get target for disconnecting TargetSource [" + this + "]"; + logger.error(msg, ex); + throw new NotSerializableException(msg + ": " + ex); } }