Migrate from soon to be deprecate SnakeYAML constructor

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

See gh-33663
This commit is contained in:
Andrey Somov 2022-12-30 15:41:16 +04:00 committed by Phillip Webb
parent 0a50b83c75
commit a095a3a888

View File

@ -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<Map<String, List<String>>> {
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));
}
}