Skip to content

Commit 172dfef

Browse files
authored
Merge pull request #231 from avaje/SentryMan-patch-3
Catch NCDF instead of using `Class.forName`
2 parents 13c2e30 + d8780d2 commit 172dfef

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

avaje-config/src/main/java/io/avaje/config/Parsers.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,21 @@ final class Parsers {
2323
}
2424

2525
private void initYamlParser() {
26-
YamlLoader yamlLoader;
27-
try {
28-
Class.forName("org.yaml.snakeyaml.Yaml");
29-
yamlLoader = new YamlLoaderSnake();
30-
} catch (ClassNotFoundException e) {
31-
yamlLoader = new YamlLoaderSimple();
32-
}
26+
var modules = ModuleLayer.boot();
27+
YamlLoader yamlLoader =
28+
modules
29+
.findModule("io.avaje.config")
30+
.map(m -> modules.findModule("org.yaml.snakeyaml").isPresent())
31+
.map(m -> (YamlLoader) new YamlLoaderSnake())
32+
.orElseGet(
33+
() -> {
34+
try {
35+
return new YamlLoaderSnake();
36+
} catch (Throwable e) {
37+
return new YamlLoaderSimple();
38+
}
39+
});
40+
3341
parserMap.put("yml", yamlLoader);
3442
parserMap.put("yaml", yamlLoader);
3543
}

0 commit comments

Comments
 (0)