From 74fb55d96b0eac9598086bc8c0a27f80bae1f5c3 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 16 Mar 2023 20:41:03 +0100 Subject: [PATCH] Update yaml compat checker --- .../java/com/viaversion/viaversion/util/Config.java | 10 +++------- .../viaversion/compatibility/YamlCompat.java | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/util/Config.java b/common/src/main/java/com/viaversion/viaversion/util/Config.java index f948df1f2..4653815ee 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/Config.java +++ b/common/src/main/java/com/viaversion/viaversion/util/Config.java @@ -39,19 +39,15 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; +@SuppressWarnings("VulnerableCodeUsages") public abstract class Config implements ConfigurationProvider { - private static final YamlCompat YAMP_COMPAT = YamlCompat.isVersion2() ? new Yaml2Compat() : new Yaml1Compat(); + private static final YamlCompat YAMP_COMPAT = YamlCompat.isVersion1() ? new Yaml1Compat() : new Yaml2Compat(); private static final ThreadLocal YAML = ThreadLocal.withInitial(() -> { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setPrettyFlow(false); options.setIndent(2); - try { - return new Yaml(YAMP_COMPAT.createSafeConstructor(), YAMP_COMPAT.createRepresenter(options), options); - } catch (NoSuchMethodError e) { - YamlCompat compat = new Yaml1Compat(); - return new Yaml(compat.createSafeConstructor(), compat.createRepresenter(options), options); - } + return new Yaml(YAMP_COMPAT.createSafeConstructor(), YAMP_COMPAT.createRepresenter(options), options); }); private final CommentStore commentStore = new CommentStore('.', 2); diff --git a/compat/snakeyaml-compat-common/src/main/java/com/viaversion/viaversion/compatibility/YamlCompat.java b/compat/snakeyaml-compat-common/src/main/java/com/viaversion/viaversion/compatibility/YamlCompat.java index 8726f560e..7a3335618 100644 --- a/compat/snakeyaml-compat-common/src/main/java/com/viaversion/viaversion/compatibility/YamlCompat.java +++ b/compat/snakeyaml-compat-common/src/main/java/com/viaversion/viaversion/compatibility/YamlCompat.java @@ -27,9 +27,9 @@ public interface YamlCompat { SafeConstructor createSafeConstructor(); - static boolean isVersion2() { + static boolean isVersion1() { try { - Representer.class.getDeclaredConstructor(DumperOptions.class); + SafeConstructor.class.getDeclaredConstructor(); return true; } catch (NoSuchMethodException e) { return false;