From 887052345ba94b1faf8f01063c53d18726cd1949 Mon Sep 17 00:00:00 2001 From: "L. Wagner" Date: Mon, 14 Oct 2024 09:15:17 +0200 Subject: [PATCH] Use yaml instance instead of static variable to enable threadsaftey Fixes https://github.com/cloudfoundry/cf-java-client/issues/1245 --- .../applications/ApplicationManifestUtilsV3.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsV3.java b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsV3.java index 8f2f4bcadd..213730cbb1 100644 --- a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsV3.java +++ b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsV3.java @@ -41,14 +41,12 @@ * Utilities for dealing with {@link ManifestV3}s. Includes the functionality to transform to and from standard CLI YAML files. */ public final class ApplicationManifestUtilsV3 extends ApplicationManifestUtilsCommon { - private static final Yaml YAML; + private static final DumperOptions dumperOptions; static { - DumperOptions dumperOptions = new DumperOptions(); + dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); dumperOptions.setExplicitStart(true); - - YAML = new Yaml(dumperOptions); } private static final Pattern FIND_VARIABLE_REGEX = @@ -104,9 +102,10 @@ public static void write(Path path, ManifestV3 manifest) { * @param out the {@link OutputStream} to write to * @param manifest the manifest to write */ - public static void write(OutputStream out, ManifestV3 manifest) { + public static void write(OutputStream out, ManifestV3 manifest) { + Yaml yaml = new Yaml(dumperOptions); try (Writer writer = new OutputStreamWriter(out)) { - YAML.dump(toYaml(manifest), writer); + yaml.dump(toYaml(manifest), writer); } catch (IOException e) { throw Exceptions.propagate(e); }