make dependency loader json logic more robust (#25)

This commit is contained in:
FalsePattern committed 2023-04-06 19:20:06 +02:00
1 parent 1d20026af0
commit c6abc0061a
1 file changed
+7 -4
@@ -284,9 +284,12 @@ public class DependencyLoaderImpl {
.map((source) -> {
//Convert source to GSON json
try (val is = source.openStream()) {
val json = new JsonParser().parse(new InputStreamReader(is)).getAsJsonObject();
if (!(json.isJsonObject() &&
json.has("identifier") &&
val jsonRaw = new JsonParser().parse(new InputStreamReader(is));
if (!jsonRaw.isJsonObject()) {
return null;
}
val json = jsonRaw.getAsJsonObject();
if (!(json.has("identifier") &&
json.get("identifier")
.getAsString()
.equals("falsepatternlib_dependencies")
@@ -300,7 +303,7 @@ public class DependencyLoaderImpl {
val root = gson.fromJson(json, DepRoot.class);
root.source(source.toString());
return root;
} catch (IOException e) {
} catch (Exception e) {
LOG.error("Failed to read json from source {}: {}", source, e);
return null;
}