Skip to content

Commit fe1bb10

Browse files
committed
fix: add null and existence checks for JSON-LD file in JsonLdExpander
1 parent 4736e28 commit fe1bb10

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/main/java/edu/kit/datamanager/ro_crate/util/JsonLdExpander.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
/**
1111
* Utility class for expanding and pruning JSON-LD documents.
12-
*
12+
* <p>
1313
* This class provides functionality to resolve references in JSON-LD based on "@id" values,
1414
* expanding the data structure by replacing references with their full content.
1515
* It also handles circular references to prevent infinite recursion.
@@ -19,6 +19,12 @@
1919
public class JsonLdExpander {
2020

2121
public static JsonNode expandAndPrune(File jsonLdFile) throws Exception {
22+
if (jsonLdFile == null) {
23+
throw new IllegalArgumentException("JSON-LD file must not be null.");
24+
}
25+
if (!jsonLdFile.exists() || !jsonLdFile.canRead()) {
26+
throw new IllegalArgumentException("JSON-LD file does not exist or cannot be read: " + jsonLdFile.getAbsolutePath());
27+
}
2228
ObjectMapper mapper = new ObjectMapper();
2329
JsonNode root = mapper.readTree(jsonLdFile);
2430
return expandAndPrune(root);

0 commit comments

Comments
 (0)