Skip to content

Fix concurrency issues in XStreamMarshaller #25017

@JakobFels

Description

@JakobFels

Just stumbled on a nasty concurrency issue in org.springframework.oxm.xstream.XStreamMarshaller.

When you forget to call afterPropertiesSet on this marshaller, the internally held XStream instance will not be initialized. Instead, it will be done in the method getXStream, which is called from both marshal and unmarshal methods.

This initialization is not guarded, and might happen concurrently. In this case, the ConverterLookup used to store converters will be shared by the XStream instances that are constructed, which can lead to strange application behaviour, since the underlying data structure is not thread safe.

In our application, it lead to very strange errors during XML marshalling/unmarshalling, since a couple of converters were missing. This happened whenever our app process scaled up during high load.

I see 2 possible solutions:

  • throw an exception in case afterPropertiesSet is not called on an instance
  • make XStream initialization thread safe

Spring version affected is 5.2.5.RELEASE

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions