Migrate from soon to be deprecate SnakeYAML constructor

Update `LayersIndex` to use constructor that accepts
`LoaderOptions`.

See gh-33663
pull/33918/head
Andrey Somov 2 years ago committed by Phillip Webb
parent 0a50b83c75
commit a095a3a888

@ -25,6 +25,7 @@ import java.util.Map;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.constructor.Constructor;
@ -45,7 +46,11 @@ class LayersIndex extends ArrayList<Map<String, List<String>>> {
String indexPath = (archiveFile.getName().endsWith(".war") ? "WEB-INF/layers.idx" : "BOOT-INF/layers.idx"); String indexPath = (archiveFile.getName().endsWith(".war") ? "WEB-INF/layers.idx" : "BOOT-INF/layers.idx");
try (JarFile jarFile = new JarFile(archiveFile)) { try (JarFile jarFile = new JarFile(archiveFile)) {
ZipEntry indexEntry = jarFile.getEntry(indexPath); 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)); return yaml.load(jarFile.getInputStream(indexEntry));
} }
} }

Loading…
Cancel
Save