You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/02/27 19:42:57 UTC

[commons-configuration] branch master updated: Support SnakeYAML 2.0 (#282)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-configuration.git


The following commit(s) were added to refs/heads/master by this push:
     new 153d828c Support SnakeYAML 2.0 (#282)
153d828c is described below

commit 153d828c23b5fe0e401822898db7f28b3ba73671
Author: strangelookingnerd <49...@users.noreply.github.com>
AuthorDate: Mon Feb 27 20:42:50 2023 +0100

    Support SnakeYAML 2.0 (#282)
---
 .../commons/configuration2/YAMLConfiguration.java     | 19 ++-----------------
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/src/main/java/org/apache/commons/configuration2/YAMLConfiguration.java b/src/main/java/org/apache/commons/configuration2/YAMLConfiguration.java
index 4732e3f3..7f392ccd 100644
--- a/src/main/java/org/apache/commons/configuration2/YAMLConfiguration.java
+++ b/src/main/java/org/apache/commons/configuration2/YAMLConfiguration.java
@@ -24,13 +24,12 @@ import java.io.Writer;
 import java.util.Map;
 
 import org.apache.commons.configuration2.ex.ConfigurationException;
-import org.apache.commons.configuration2.ex.ConfigurationRuntimeException;
 import org.apache.commons.configuration2.io.InputStreamSupport;
 import org.apache.commons.configuration2.tree.ImmutableNode;
 import org.yaml.snakeyaml.DumperOptions;
 import org.yaml.snakeyaml.LoaderOptions;
 import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.constructor.Constructor;
+import org.yaml.snakeyaml.constructor.SafeConstructor;
 import org.yaml.snakeyaml.representer.Representer;
 
 /**
@@ -124,21 +123,7 @@ public class YAMLConfiguration extends AbstractYAMLBasedConfiguration implements
      * @return the {@code Yaml} instance for loading a file
      */
     private static Yaml createYamlForReading(final LoaderOptions options) {
-        return new Yaml(createClassLoadingDisablingConstructor(), new Representer(), new DumperOptions(), options);
+        return new Yaml(new SafeConstructor(options), new Representer(new DumperOptions()), new DumperOptions(), options);
     }
 
-    /**
-     * Returns a {@code Constructor} object for the YAML parser that prevents all classes from being loaded. This
-     * effectively disables the dynamic creation of Java objects that are declared in YAML files to be loaded.
-     *
-     * @return the {@code Constructor} preventing object creation
-     */
-    private static Constructor createClassLoadingDisablingConstructor() {
-        return new Constructor() {
-            @Override
-            protected Class<?> getClassForName(final String name) {
-                throw new ConfigurationRuntimeException("Class instantiation is disabled.");
-            }
-        };
-    }
 }