Commit 51e0426b authored by Emmanuel Bourg's avatar Emmanuel Bourg

Fixed the compatibility with the version of SnakeYAML in Debian

parent a401e07e
......@@ -3,6 +3,7 @@ libspring-java (4.3.15-1) UNRELEASED; urgency=medium
* Team upload.
* New upstream release
- Refreshed the patches
* Fixed the compatibility with the version of SnakeYAML in Debian
* Standards-Version updated to 4.2.1
* Use salsa.debian.org Vcs-* URLs
......
Description: Fixes the compatibility with the version of SnakeYAML in Debian
Origin: backport, https://github.com/spring-projects/spring-framework/commit/138b0d0bbdf65b0da181a06e5fc79cda05fb1e71
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java
@@ -18,7 +18,6 @@
import java.io.IOException;
import java.io.Reader;
-import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -26,14 +25,11 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.constructor.Constructor;
-import org.yaml.snakeyaml.nodes.MappingNode;
-import org.yaml.snakeyaml.parser.ParserException;
import org.yaml.snakeyaml.reader.UnicodeReader;
import org.springframework.core.CollectionFactory;
@@ -143,9 +139,14 @@
/**
* Create the {@link Yaml} instance to use.
+ * <p>The default implementation sets the "allowDuplicateKeys" flag to {@code false},
+ * enabling built-in duplicate key handling in SnakeYAML 1.18+.
+ * @see LoaderOptions#setAllowDuplicateKeys(boolean)
*/
protected Yaml createYaml() {
- return new Yaml(new StrictMapAppenderConstructor());
+ LoaderOptions options = new LoaderOptions();
+ options.setAllowDuplicateKeys(false);
+ return new Yaml(options);
}
private boolean process(MatchCallback callback, Yaml yaml, Resource resource) {
@@ -389,45 +390,4 @@
FIRST_FOUND
}
-
- /**
- * A specialized {@link Constructor} that checks for duplicate keys.
- */
- protected static class StrictMapAppenderConstructor extends Constructor {
-
- // Declared as public for use in subclasses
- public StrictMapAppenderConstructor() {
- super();
- }
-
- @Override
- protected Map<Object, Object> constructMapping(MappingNode node) {
- try {
- return super.constructMapping(node);
- }
- catch (IllegalStateException ex) {
- throw new ParserException("while parsing MappingNode",
- node.getStartMark(), ex.getMessage(), node.getEndMark());
- }
- }
-
- @Override
- protected Map<Object, Object> createDefaultMap() {
- final Map<Object, Object> delegate = super.createDefaultMap();
- return new AbstractMap<Object, Object>() {
- @Override
- public Object put(Object key, Object value) {
- if (delegate.containsKey(key)) {
- throw new IllegalStateException("Duplicate key: " + key);
- }
- return delegate.put(key, value);
- }
- @Override
- public Set<Entry<Object, Object>> entrySet() {
- return delegate.entrySet();
- }
- };
- }
- }
-
}
......@@ -16,3 +16,4 @@
0045-ignore-caffeine.patch
0046-jruby-compatibility.patch
0047-ejb-api-compatibility.patch
0048-snakeyaml-compatibility.patch
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment