1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -97,7 +97,7 @@ else if (target instanceof DisposableBean) {
97
97
98
98
private void readObject (ObjectInputStream ois ) throws IOException , ClassNotFoundException {
99
99
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" );
101
101
}
102
102
103
103
/**
@@ -113,13 +113,15 @@ protected Object writeReplace() throws ObjectStreamException {
113
113
logger .debug ("Disconnecting TargetSource [" + this + "]" );
114
114
}
115
115
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 ()));
118
120
}
119
121
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 );
123
125
}
124
126
}
125
127
0 commit comments