Skip to content

Commit b64c9d9

Browse files
committed
improves error message when "InputStream not found"
1 parent 154e900 commit b64c9d9

File tree

1 file changed

+8
-5
lines changed
  • src/main/java/io/zenwave360/jsonrefparser/parser

1 file changed

+8
-5
lines changed

src/main/java/io/zenwave360/jsonrefparser/parser/Parser.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,28 @@ public static void withResourceClassLoader(ClassLoader resourceClassLoader) {
4343

4444
public static ExtendedJsonContext parse(URI uri) throws IOException {
4545
if("classpath".contentEquals(uri.getScheme())) {
46-
return parse(resourceClassLoader.getResourceAsStream(uri.getPath().replaceFirst("^/", "")));
46+
return parse(resourceClassLoader.getResourceAsStream(uri.getPath().replaceFirst("^/", "")), uri);
4747
}
4848
// TODO: it does not support yet parsing http/https files directly
49-
return parse(new FileInputStream(new File(uri)));
49+
return parse(new FileInputStream(new File(uri)), uri);
5050
}
5151

5252
public static ExtendedJsonContext parse(File file) throws IOException {
53-
return parse(new FileInputStream(file));
53+
return parse(new FileInputStream(file), file);
5454
}
5555

5656
public static ExtendedJsonContext parse(String content) {
5757
try {
58-
return parse(new ByteArrayInputStream(content.getBytes()));
58+
return parse(new ByteArrayInputStream(content.getBytes()), "string");
5959
} catch (IOException e) {
6060
throw new RuntimeException(e);
6161
}
6262
}
6363

64-
public static ExtendedJsonContext parse(InputStream inputStream) throws IOException {
64+
public static ExtendedJsonContext parse(InputStream inputStream, Object source) throws IOException {
65+
if (inputStream == null) {
66+
throw new IllegalArgumentException("$RefParser.parse(): InputStream not found [" + source + "]");
67+
}
6568
ObjectMapper mapper = new ObjectMapper(new CustomYAMLFactory());
6669
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
6770
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

0 commit comments

Comments
 (0)