Skip to content

Commit 19cf32b

Browse files
Yaml instance in YamlFilesImporter is not thread-safe
1 parent 40196aa commit 19cf32b

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

consul-populate-core/src/main/java/com/frogdevelopment/consul/populate/files/YamlFilesImporter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public final class YamlFilesImporter extends FilesImporter {
2424

2525
private static final List<String> EXTENSIONS = List.of("yaml", "yml");
2626

27-
private final Yaml yaml = new Yaml();
27+
private final ThreadLocal<Yaml> yaml = ThreadLocal.withInitial(Yaml::new);
2828

2929
/**
3030
* Constructor
@@ -45,7 +45,7 @@ protected boolean isExtensionAccepted(@NonNull final String extension) {
4545
@Override
4646
protected SequencedMap<String, Object> readFile(@NonNull final File file) throws IOException {
4747
try (final var reader = Files.newBufferedReader(file.toPath())) {
48-
return yaml.load(reader);
48+
return yaml.get().load(reader);
4949
}
5050
}
5151

@@ -55,6 +55,6 @@ protected String writeValueAsString(@NonNull final Map<String, Object> map) {
5555
if (map == null || map.isEmpty()) {
5656
return "";
5757
}
58-
return yaml.dumpAsMap(map);
58+
return yaml.get().dumpAsMap(map);
5959
}
6060
}

0 commit comments

Comments
 (0)