Skip to content

Commit fb37fc5

Browse files
committed
optimize
1 parent 0067144 commit fb37fc5

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

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

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

2525
private void initYamlParser() {
26-
YamlLoader yamlLoader;
27-
if (ModuleLayer.boot().findModule("org.yaml.snakeyaml").isPresent()) {
28-
yamlLoader = new YamlLoaderSnake();
29-
parserMap.put("yml", yamlLoader);
30-
parserMap.put("yaml", yamlLoader);
31-
return;
32-
}
33-
try {
34-
yamlLoader = new YamlLoaderSnake();
35-
} catch (NoClassDefFoundError e) {
36-
yamlLoader = new YamlLoaderSimple();
37-
}
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 (NoClassDefFoundError e) {
37+
return new YamlLoaderSimple();
38+
}
39+
});
40+
3841
parserMap.put("yml", yamlLoader);
3942
parserMap.put("yaml", yamlLoader);
4043
}

0 commit comments

Comments
 (0)