From cbb1dd46c0453f9d86a703155dcf4231640ae922 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sun, 9 Oct 2022 11:45:05 +1100 Subject: [PATCH] Remove obsolete workaround for SnakeYAML 100 comment limit By: md_5 --- .../bukkit/configuration/file/BukkitYaml.java | 74 ------------------- .../configuration/file/YamlConfiguration.java | 2 +- 2 files changed, 1 insertion(+), 75 deletions(-) delete mode 100644 paper-api/src/main/java/org/bukkit/configuration/file/BukkitYaml.java diff --git a/paper-api/src/main/java/org/bukkit/configuration/file/BukkitYaml.java b/paper-api/src/main/java/org/bukkit/configuration/file/BukkitYaml.java deleted file mode 100644 index ba20419c6d..0000000000 --- a/paper-api/src/main/java/org/bukkit/configuration/file/BukkitYaml.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.bukkit.configuration.file; - -import java.io.IOException; -import java.io.Writer; -import java.lang.reflect.Field; -import java.util.ArrayDeque; -import java.util.Queue; -import org.jetbrains.annotations.NotNull; -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.LoaderOptions; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.comments.CommentEventsCollector; -import org.yaml.snakeyaml.comments.CommentType; -import org.yaml.snakeyaml.constructor.BaseConstructor; -import org.yaml.snakeyaml.emitter.Emitter; -import org.yaml.snakeyaml.error.YAMLException; -import org.yaml.snakeyaml.events.Event; -import org.yaml.snakeyaml.nodes.Node; -import org.yaml.snakeyaml.representer.Representer; -import org.yaml.snakeyaml.serializer.Serializer; - -final class BukkitYaml extends Yaml { - - private static final Field events; - private static final Field blockCommentsCollector; - private static final Field inlineCommentsCollector; - - private static Field getEmitterField(String name) { - Field field = null; - try { - field = Emitter.class.getDeclaredField(name); - field.setAccessible(true); - } catch (ReflectiveOperationException ex) { - // Ignore as a fail-safe fallback - } - return field; - } - - static { - events = getEmitterField("events"); - blockCommentsCollector = getEmitterField("blockCommentsCollector"); - inlineCommentsCollector = getEmitterField("inlineCommentsCollector"); - } - - public BukkitYaml(@NotNull BaseConstructor constructor, @NotNull Representer representer, @NotNull DumperOptions dumperOptions, @NotNull LoaderOptions loadingConfig) { - super(constructor, representer, dumperOptions, loadingConfig); - } - - @Override - public void serialize(@NotNull Node node, @NotNull Writer output) { - Emitter emitter = new Emitter(output, dumperOptions); - if (events != null && blockCommentsCollector != null && inlineCommentsCollector != null) { - Queue newEvents = new ArrayDeque<>(100); - - try { - events.set(emitter, newEvents); - blockCommentsCollector.set(emitter, new CommentEventsCollector(newEvents, CommentType.BLANK_LINE, CommentType.BLOCK)); - inlineCommentsCollector.set(emitter, new CommentEventsCollector(newEvents, CommentType.IN_LINE)); - } catch (ReflectiveOperationException ex) { - // Don't ignore this as we could be in an inconsistent state - throw new RuntimeException("Could not update Yaml event queue", ex); - } - } - - Serializer serializer = new Serializer(emitter, resolver, dumperOptions, null); - try { - serializer.open(); - serializer.serialize(node); - serializer.close(); - } catch (IOException ex) { - throw new YAMLException(ex); - } - } -} diff --git a/paper-api/src/main/java/org/bukkit/configuration/file/YamlConfiguration.java b/paper-api/src/main/java/org/bukkit/configuration/file/YamlConfiguration.java index 9e200e149a..559b876d11 100644 --- a/paper-api/src/main/java/org/bukkit/configuration/file/YamlConfiguration.java +++ b/paper-api/src/main/java/org/bukkit/configuration/file/YamlConfiguration.java @@ -66,7 +66,7 @@ public class YamlConfiguration extends FileConfiguration { yamlLoaderOptions.setMaxAliasesForCollections(Integer.MAX_VALUE); // SPIGOT-5881: Not ideal, but was default pre SnakeYAML 1.26 yamlLoaderOptions.setCodePointLimit(Integer.MAX_VALUE); // SPIGOT-7161: Not ideal, but was default pre SnakeYAML 1.32 - yaml = new BukkitYaml(constructor, representer, yamlDumperOptions, yamlLoaderOptions); + yaml = new Yaml(constructor, representer, yamlDumperOptions, yamlLoaderOptions); } @NotNull