Use SingletonSupplier for XStream instance in XStreamMarshaller
Closes gh-25017
This commit is contained in:
parent
ce11fdfa80
commit
4805288122
|
|
@ -84,6 +84,7 @@ import org.springframework.oxm.support.AbstractMarshaller;
|
|||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.function.SingletonSupplier;
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
/**
|
||||
|
|
@ -187,8 +188,7 @@ public class XStreamMarshaller extends AbstractMarshaller implements BeanClassLo
|
|||
|
||||
private ClassLoader beanClassLoader = new CompositeClassLoader();
|
||||
|
||||
@Nullable
|
||||
private volatile XStream xstream;
|
||||
private final SingletonSupplier<XStream> xstream = SingletonSupplier.of(this::buildXStream);
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -407,12 +407,12 @@ public class XStreamMarshaller extends AbstractMarshaller implements BeanClassLo
|
|||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
this.xstream = buildXStream();
|
||||
// no-op due to use of SingletonSupplier for the XStream field.
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the native XStream delegate to be used by this marshaller,
|
||||
* delegating to {@link #constructXStream()}, {@link #configureXStream}
|
||||
* delegating to {@link #constructXStream}, {@link #configureXStream},
|
||||
* and {@link #customizeXStream}.
|
||||
*/
|
||||
protected XStream buildXStream() {
|
||||
|
|
@ -617,21 +617,11 @@ public class XStreamMarshaller extends AbstractMarshaller implements BeanClassLo
|
|||
* <p><b>NOTE: This method has been marked as final as of Spring 4.0.</b>
|
||||
* It can be used to access the fully configured XStream for marshalling
|
||||
* but not configuration purposes anymore.
|
||||
* <p>As of Spring Framework 5.2.7, creation of the {@link XStream} instance
|
||||
* <p>As of Spring Framework 5.1.16, creation of the {@link XStream} instance
|
||||
* returned by this method is thread safe.
|
||||
*/
|
||||
public final XStream getXStream() {
|
||||
XStream xs = this.xstream;
|
||||
if (xs == null) {
|
||||
synchronized (this) {
|
||||
xs = this.xstream;
|
||||
if (xs == null) {
|
||||
xs = buildXStream();
|
||||
this.xstream = xs;
|
||||
}
|
||||
}
|
||||
}
|
||||
return xs;
|
||||
return this.xstream.obtain();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue