Skip to content

Commit 5acad5f

Browse files
authored
Merge pull request #2612 from ryanjbaxter/cherry-pick-snakeyaml-2.0
Cherry Pick For 17.x - Compensating changes for SnakeYAML 2.0
2 parents eac8035 + 182a6fd commit 5acad5f

File tree

5 files changed

+8
-4
lines changed

5 files changed

+8
-4
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4444

4545
<javax.annotation.version>1.3.2</javax.annotation.version>
46-
<snakeyaml.version>1.33</snakeyaml.version>
4746
<slf4j.version>2.0.5</slf4j.version>
47+
<snakeyaml.version>2.0</snakeyaml.version>
4848
<caffeine.version>2.9.3</caffeine.version>
4949
<protobuf.version>3.21.10</protobuf.version>
5050
<junit.version>4.13</junit.version>

util/src/main/java/io/kubernetes/client/util/FilePersister.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.io.IOException;
1818
import java.util.ArrayList;
1919
import java.util.HashMap;
20+
import org.yaml.snakeyaml.LoaderOptions;
2021
import org.yaml.snakeyaml.Yaml;
2122
import org.yaml.snakeyaml.constructor.SafeConstructor;
2223

@@ -51,7 +52,7 @@ public void save(
5152
// Note this is imperfect, should protect against other processes writing this file too...
5253
synchronized (configFile) {
5354
try (FileWriter fw = new FileWriter(configFile)) {
54-
Yaml yaml = new Yaml(new SafeConstructor());
55+
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()));
5556
yaml.dump(config, fw);
5657
fw.flush();
5758
}

util/src/main/java/io/kubernetes/client/util/KubeConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.commons.codec.binary.Base64;
3838
import org.slf4j.Logger;
3939
import org.slf4j.LoggerFactory;
40+
import org.yaml.snakeyaml.LoaderOptions;
4041
import org.yaml.snakeyaml.Yaml;
4142
import org.yaml.snakeyaml.constructor.SafeConstructor;
4243

@@ -83,7 +84,7 @@ public static void registerAuthenticator(Authenticator auth) {
8384

8485
/** Load a Kubernetes config from a Reader */
8586
public static KubeConfig loadKubeConfig(Reader input) {
86-
Yaml yaml = new Yaml(new SafeConstructor());
87+
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()));
8788
Object config = yaml.load(input);
8889
Map<String, Object> configMap = (Map<String, Object>) config;
8990

util/src/main/java/io/kubernetes/client/util/Yaml.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ private Object constructDateTime(ScalarNode node) {
269269

270270
public static class CustomRepresenter extends Representer {
271271
public CustomRepresenter() {
272+
super(new DumperOptions());
272273
this.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
273274
this.representers.put(IntOrString.class, new RepresentIntOrString());
274275
this.representers.put(byte[].class, new RepresentByteArray());

util/src/main/java/io/kubernetes/client/util/generic/dynamic/Dynamics.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
import com.google.gson.JsonElement;
1717
import io.kubernetes.client.openapi.JSON;
1818
import java.util.Map;
19+
import org.yaml.snakeyaml.LoaderOptions;
1920
import org.yaml.snakeyaml.Yaml;
2021
import org.yaml.snakeyaml.constructor.SafeConstructor;
2122

2223
public class Dynamics {
2324

2425
static final JSON internalJSONCodec = new JSON();
25-
static final Yaml internalYamlCodec = new Yaml(new SafeConstructor());
26+
static final Yaml internalYamlCodec = new Yaml(new SafeConstructor(new LoaderOptions()));
2627

2728
public static DynamicKubernetesObject newFromJson(String jsonContent) {
2829
return newFromJson(internalJSONCodec.getGson(), jsonContent);

0 commit comments

Comments
 (0)