From c89fb745f72ef468f1b4fd67931ce278e621ce30 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 25 Jul 2018 19:03:13 +0200 Subject: [PATCH] ListBasedXMLEventReader uses defensive modifiable copy of given List (cherry picked from commit 9ab63b8494ae490eeccbffa5cfc1a32bf439fee5) --- .../util/xml/ListBasedXMLEventReader.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java b/spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java index f409ee0d31..ed79471b3d 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java +++ b/spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.util.xml; -import java.util.Collections; +import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; import javax.xml.stream.events.XMLEvent; @@ -25,7 +25,8 @@ import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** - * Implementation of {@code XMLEventReader} based on a list of {@link XMLEvent}s. + * Implementation of {@code XMLEventReader} based on a {@link List} + * of {@link XMLEvent} elements. * * @author Arjen Poutsma * @since 5.0 @@ -38,8 +39,8 @@ class ListBasedXMLEventReader extends AbstractXMLEventReader { public ListBasedXMLEventReader(List events) { - Assert.notNull(events, "'events' must not be null"); - this.events = Collections.unmodifiableList(events); + Assert.notNull(events, "XMLEvent List must not be null"); + this.events = new ArrayList<>(events); }