From a095a3a888d4692f30e4eaf1b57e908913679358 Mon Sep 17 00:00:00 2001 From: Andrey Somov Date: Fri, 30 Dec 2022 15:41:16 +0400 Subject: [PATCH 1/2] Migrate from soon to be deprecate SnakeYAML constructor Update `LayersIndex` to use constructor that accepts `LoaderOptions`. See gh-33663 --- .../org/springframework/boot/image/paketo/LayersIndex.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/LayersIndex.java b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/LayersIndex.java index 34460dbbe6..004e70223c 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/LayersIndex.java +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/LayersIndex.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.jar.JarFile; import java.util.zip.ZipEntry; +import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; @@ -45,7 +46,11 @@ class LayersIndex extends ArrayList>> { String indexPath = (archiveFile.getName().endsWith(".war") ? "WEB-INF/layers.idx" : "BOOT-INF/layers.idx"); try (JarFile jarFile = new JarFile(archiveFile)) { ZipEntry indexEntry = jarFile.getEntry(indexPath); - Yaml yaml = new Yaml(new Constructor(LayersIndex.class)); + LoaderOptions loaderOptions = new LoaderOptions(); + loaderOptions.setAllowDuplicateKeys(false); + loaderOptions.setMaxAliasesForCollections(Integer.MAX_VALUE); + loaderOptions.setAllowRecursiveKeys(true); + Yaml yaml = new Yaml(new Constructor(LayersIndex.class, loaderOptions)); return yaml.load(jarFile.getInputStream(indexEntry)); } } From 2faede6245f657d8e7b87167dadbed1a9411c18b Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 19 Jan 2023 11:51:13 -0800 Subject: [PATCH 2/2] Polish 'Migrate from soon to be deprecate SnakeYAML constructor' See gh-33663 --- .../boot/image/paketo/LayersIndex.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/LayersIndex.java b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/LayersIndex.java index 004e70223c..4c5ed9edeb 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/LayersIndex.java +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/LayersIndex.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,13 +46,17 @@ class LayersIndex extends ArrayList>> { String indexPath = (archiveFile.getName().endsWith(".war") ? "WEB-INF/layers.idx" : "BOOT-INF/layers.idx"); try (JarFile jarFile = new JarFile(archiveFile)) { ZipEntry indexEntry = jarFile.getEntry(indexPath); - LoaderOptions loaderOptions = new LoaderOptions(); - loaderOptions.setAllowDuplicateKeys(false); - loaderOptions.setMaxAliasesForCollections(Integer.MAX_VALUE); - loaderOptions.setAllowRecursiveKeys(true); - Yaml yaml = new Yaml(new Constructor(LayersIndex.class, loaderOptions)); + Yaml yaml = new Yaml(new Constructor(LayersIndex.class, getLoaderOptions())); return yaml.load(jarFile.getInputStream(indexEntry)); } } + private static LoaderOptions getLoaderOptions() { + LoaderOptions loaderOptions = new LoaderOptions(); + loaderOptions.setAllowDuplicateKeys(false); + loaderOptions.setMaxAliasesForCollections(Integer.MAX_VALUE); + loaderOptions.setAllowRecursiveKeys(true); + return loaderOptions; + } + }