TargetSource.getTarget() is nullable again (for compatibility with MethodInvocation.getThis)

Issue: SPR-15651
This commit is contained in:
Juergen Hoeller 2017-06-13 03:11:36 +02:00
parent 47ec966757
commit 738160538e
1 changed files with 9 additions and 7 deletions

View File

@ -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);
}
}