diff --git a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsCommon.java b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsCommon.java index 932809d56a..8b9706b83b 100644 --- a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsCommon.java +++ b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsCommon.java @@ -48,14 +48,12 @@ abstract class ApplicationManifestUtilsCommon { static final int GIBI = 1_024; - static final Yaml YAML; + static final DumperOptions dumperOptions; static { - DumperOptions dumperOptions = new DumperOptions(); + dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); dumperOptions.setExplicitStart(true); - - YAML = new Yaml(dumperOptions); } static final Pattern FIND_VARIABLE_REGEX = Pattern.compile("\\(\\(([a-zA-Z]\\w+)\\)\\)"); @@ -276,10 +274,12 @@ static void asString( @SuppressWarnings("unchecked") static Map deserialize(Path path) { + Yaml yaml = new Yaml(dumperOptions); + AtomicReference> root = new AtomicReference<>(); try (InputStream in = Files.newInputStream(path, StandardOpenOption.READ)) { - root.set((Map) YAML.load(in)); + root.set((Map) yaml.load(in)); } catch (IOException e) { throw Exceptions.propagate(e); } 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); }