Skip to content

Commit 7381605

Browse files
committed
TargetSource.getTarget() is nullable again (for compatibility with MethodInvocation.getThis)
Issue: SPR-15651
1 parent 47ec966 commit 7381605

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

spring-aop/src/main/java/org/springframework/aop/target/AbstractPrototypeBasedTargetSource.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -97,7 +97,7 @@ else if (target instanceof DisposableBean) {
9797

9898
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
9999
throw new NotSerializableException("A prototype-based TargetSource itself is not deserializable - " +
100-
"just a disconnected SingletonTargetSource is");
100+
"just a disconnected SingletonTargetSource or EmptyTargetSource is");
101101
}
102102

103103
/**
@@ -113,13 +113,15 @@ protected Object writeReplace() throws ObjectStreamException {
113113
logger.debug("Disconnecting TargetSource [" + this + "]");
114114
}
115115
try {
116-
// Create disconnected SingletonTargetSource.
117-
return new SingletonTargetSource(getTarget());
116+
// Create disconnected SingletonTargetSource/EmptyTargetSource.
117+
Object target = getTarget();
118+
return (target != null ? new SingletonTargetSource(target) :
119+
EmptyTargetSource.forClass(getTargetClass()));
118120
}
119121
catch (Exception ex) {
120-
logger.error("Cannot get target for disconnecting TargetSource [" + this + "]", ex);
121-
throw new NotSerializableException(
122-
"Cannot get target for disconnecting TargetSource [" + this + "]: " + ex);
122+
String msg = "Cannot get target for disconnecting TargetSource [" + this + "]";
123+
logger.error(msg, ex);
124+
throw new NotSerializableException(msg + ": " + ex);
123125
}
124126
}
125127

0 commit comments

Comments
 (0)