{"record":{"id":"8b5113c8c3890d41","repo":"spring-projects/spring-ai","slug":"error-reading-json-resource","errorCode":null,"errorMessage":"Error reading JSON resource","messagePattern":"Error reading JSON resource","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-commons/src/main/java/org/springframework/ai/reader/JsonReader.java","lineNumber":134,"sourceCode":"\t/**\n\t * Retrieves documents from the JSON resource using a JSON Pointer.\n\t * @param pointer A JSON Pointer string (RFC 6901) to locate the desired element\n\t * @return A list of Documents parsed from the located JSON element\n\t * @throws RuntimeException if the JSON cannot be parsed or the pointer is invalid\n\t */\n\tpublic List<Document> get(String pointer) {\n\t\ttry {\n\t\t\tJsonNode rootNode = JsonMapper.shared().readTree(this.resource.getInputStream());\n\t\t\tJsonNode targetNode = rootNode.at(pointer);\n\n\t\t\tif (targetNode.isMissingNode()) {\n\t\t\t\tthrow new IllegalArgumentException(\"Invalid JSON Pointer: \" + pointer);\n\t\t\t}\n\n\t\t\treturn get(targetNode);\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new RuntimeException(\"Error reading JSON resource\", e);\n\t\t}\n\t}\n\n}\n","sourceCodeStart":116,"sourceCodeEnd":139,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/spring-ai-commons/src/main/java/org/springframework/ai/reader/JsonReader.java#L116-L139","documentation":"In the same get(String pointer) method, any IOException from reading the underlying resource stream is wrapped as RuntimeException('Error reading JSON resource'). Unlike [426] (which wraps parse failures of the node-tree path), this is the pointer-variant entry point and gives a descriptive message with the IOException as cause.","triggerScenarios":"jsonReader.get(\"/path\") where resource.getInputStream() throws — file missing, unreadable, or stream interrupted.","commonSituations":"Wrong classpath resource name, file moved/deleted after JsonReader construction, or reading from a flaky remote resource (HTTP/URL-based Resource).","solutions":["Check resource.exists() and resource.isReadable() before constructing JsonReader","Read the resource once into a byte[] and use a ByteArrayResource for stable repeated reads","Catch RuntimeException and inspect getCause() (IOException) for the underlying reason","Verify the resolved path with resource.getDescription()/getURL()"],"exampleFix":"// before\nJsonReader reader = new JsonReader(new FileSystemResource(cfgPath));\nList<Document> docs = reader.get(\"/records\");\n// after\nResource res = new FileSystemResource(cfgPath);\nAssert.isTrue(res.exists() && res.isReadable(), \"Cannot read JSON: \" + cfgPath);\nJsonReader reader = new JsonReader(res);\nList<Document> docs = reader.get(\"/records\");","handlingStrategy":"validation","validationCode":"Assert.isTrue(resource.exists() && resource.isReadable(), \"Cannot read JSON resource: \" + resource.getDescription());","typeGuard":null,"tryCatchPattern":"try {\n    docs = jsonReader.get(pointer);\n} catch (RuntimeException e) {\n    if (\"Error reading JSON resource\".equals(e.getMessage())) {\n        throw new UncheckedIOException((IOException) e.getCause());\n    }\n    throw e;\n}","preventionTips":["Load the resource once into a ByteArrayResource for stable reads","Verify resolved paths with resource.getDescription()","Avoid holding JsonReader open over removable/network storage"],"tags":["json","io","reader"],"backgroundTag":"file-read-failed","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}