Skip to content

Commit c6abc00

Browse files
committed
make dependency loader json logic more robust (#25)
1 parent 1d20026 commit c6abc00

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main/java/com/falsepattern/lib/internal/impl/dependencies/DependencyLoaderImpl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,12 @@ public static void scanDeps() {
284284
.map((source) -> {
285285
//Convert source to GSON json
286286
try (val is = source.openStream()) {
287-
val json = new JsonParser().parse(new InputStreamReader(is)).getAsJsonObject();
288-
if (!(json.isJsonObject() &&
289-
json.has("identifier") &&
287+
val jsonRaw = new JsonParser().parse(new InputStreamReader(is));
288+
if (!jsonRaw.isJsonObject()) {
289+
return null;
290+
}
291+
val json = jsonRaw.getAsJsonObject();
292+
if (!(json.has("identifier") &&
290293
json.get("identifier")
291294
.getAsString()
292295
.equals("falsepatternlib_dependencies")
@@ -300,7 +303,7 @@ public static void scanDeps() {
300303
val root = gson.fromJson(json, DepRoot.class);
301304
root.source(source.toString());
302305
return root;
303-
} catch (IOException e) {
306+
} catch (Exception e) {
304307
LOG.error("Failed to read json from source {}: {}", source, e);
305308
return null;
306309
}

0 commit comments

Comments
 (0)