Skip to content

Commit 5d87933

Browse files
committed
error handling for classpath schema client
1 parent 721c1bc commit 5d87933

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

core/src/main/java/org/everit/json/schema/loader/ClassPathAwareSchemaClient.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import static java.util.Collections.unmodifiableList;
55
import static java.util.Objects.requireNonNull;
66

7+
import java.io.IOException;
78
import java.io.InputStream;
9+
import java.io.UncheckedIOException;
810
import java.util.List;
911
import java.util.Optional;
1012

@@ -19,9 +21,17 @@ class ClassPathAwareSchemaClient implements SchemaClient {
1921
}
2022

2123
@Override public InputStream get(String url) {
22-
return handleProtocol(url)
23-
.map(this::loadFromClasspath)
24-
.orElseGet(() -> fallbackClient.get(url));
24+
Optional<String> maybeString = handleProtocol(url);
25+
if(maybeString.isPresent()) {
26+
InputStream stream = this.loadFromClasspath(maybeString.get());
27+
if(stream != null) {
28+
return stream;
29+
} else {
30+
throw new UncheckedIOException(new IOException(String.format("Could not find %s", url)));
31+
}
32+
} else {
33+
return fallbackClient.get(url);
34+
}
2535
}
2636

2737
private InputStream loadFromClasspath(String str) {

0 commit comments

Comments
 (0)