Skip to content

How to maintain backwards compatibility with null vs empty collections when going from 1.4.4 to 1.4.5? #422

@bmr-exerp

Description

@bmr-exerp

I'm working on upgrading the XStream version used at my company. We have a 'workflow import' feature that takes an XML file and unmarshals it to a graph of JPA entities. A snippet of the XML:

<workflowData>
	<workflows>
		<workflow id="1">
...
			<steps>
				<step reference="2"/>					
				<step reference="3"/>
			</steps>
		</workflow>
	</workflows>
...

This is expected to be unmarshalled into a Workflow JPA entity. The Workflow entity has two fields of interest:

	@LazyCollection(LazyCollectionOption.FALSE)
	@OneToMany(mappedBy = "workflow", cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@IndexColumn(name = "workflow_id")
	@Fetch(FetchMode.JOIN)
	private Set<TaskStep> steps = new HashSet<TaskStep>();

	@LazyCollection(LazyCollectionOption.FALSE)
	@OneToMany(mappedBy = "workflow", cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@IndexColumn(name = "workflow_id")
	@Fetch(FetchMode.JOIN)
	private Set<TaskProgress> taskProgresses = new HashSet<TaskProgress>();

We configure the XStream appropriately, e.g. using xstream.alias("step", TaskStep.class); to map "step" to a TaskStep entity.

When migrating past 1.4.4 of XStream, two issues arise related to these two fields.

  1. The TaskStep JPA class, which defines its parent Workflow as a @ManyToOne field (the inverse of the first field in the XML above), no longer sees the field being set. I.e. in 1.4.4, Workflow.steps is a collection of TaskStep, with the TaskStep.workflow of each item in that collection being correctly set to its parent workflow. But in 1.4.5, TaskStep.workflow is being set to null. The step being referenced in the XML (<step reference="3"/>) does not explicitly reference the workflow to which it belongs, but it's correctly inferred in 1.4.4 and not in 1.4.5.
  2. The XML snippet mentioned contains no XML element corresponding to the taskProgresses collection. In 1.4.4, this is not a problem, and the value of Workflow.taskProgresses after unmarshalling is an empty hashset. In 1.4.5, the value of this field on the unmarshalled JPA entity is null, rather than an empty collection. This is causing a NullPointerException.

I'm unable to modify the XML provided to this import feature, and therefore I must retain backwards-compatibility. However, in my test, if I add <taskProgresses/> to the workflow XML, then the expected behaviour is preserved.

Can anyone advise?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions