{"record":{"id":"da87a281833176ae","repo":"antlr/antlr4","slug":"could-not-read-path-path","errorCode":null,"errorMessage":"Could not read path: \"+path","messagePattern":"Could not read path: \"\\+path","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"runtime/Java/src/org/antlr/v4/runtime/tree/xpath/XPath.java","lineNumber":91,"sourceCode":"\tprotected XPathElement[] elements;\n\tprotected Parser parser;\n\n\tpublic XPath(Parser parser, String path) {\n\t\tthis.parser = parser;\n\t\tthis.path = path;\n\t\telements = split(path);\n//\t\tSystem.out.println(Arrays.toString(elements));\n\t}\n\n\t// TODO: check for invalid token/rule names, bad syntax\n\n\tpublic XPathElement[] split(String path) {\n\t\tANTLRInputStream in;\n\t\ttry {\n\t\t\tin = new ANTLRInputStream(new StringReader(path));\n\t\t}\n\t\tcatch (IOException ioe) {\n\t\t\tthrow new IllegalArgumentException(\"Could not read path: \"+path, ioe);\n\t\t}\n\t\tXPathLexer lexer = new XPathLexer(in) {\n\t\t\t@Override\n\t\t\tpublic void recover(LexerNoViableAltException e) { throw e;\t}\n\t\t};\n\t\tlexer.removeErrorListeners();\n\t\tlexer.addErrorListener(new XPathLexerErrorListener());\n\t\tCommonTokenStream tokenStream = new CommonTokenStream(lexer);\n\t\ttry {\n\t\t\ttokenStream.fill();\n\t\t}\n\t\tcatch (LexerNoViableAltException e) {\n\t\t\tint pos = lexer.getCharPositionInLine();\n\t\t\tString msg = \"Invalid tokens or characters at index \"+pos+\" in path '\"+path+\"'\";\n\t\t\tthrow new IllegalArgumentException(msg, e);\n\t\t}\n\n\t\tList<Token> tokens = tokenStream.getTokens();","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/Java/src/org/antlr/v4/runtime/tree/xpath/XPath.java#L73-L109","documentation":"XPath.split(path) wraps the ANTLRInputStream over a StringReader for the XPath path string. An IOException from a StringReader is essentially impossible in practice (reading from an in-memory string), so this IllegalArgumentException('Could not read path: ...', ioe) is a defensive wrapper that almost never fires.","triggerScenarios":"Constructing new XPath(parser, path) or calling split(path) where the StringReader throws IOException; theoretically only via a subclassed Reader or corrupted JVM state.","commonSituations":"Practically unreachable; if seen, it indicates a custom/patched runtime rather than normal XPath usage.","solutions":["Treat occurrence as a runtime environment anomaly: verify the antlr4 runtime jar is unmodified","Ensure the path string is a plain java.lang.String, not wrapped by any custom Reader machinery"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { new XPath(parser, path); } catch (IllegalArgumentException e) { /* inspect cause for IOException; normally unreachable */ }","preventionTips":["Keep the runtime jar stock and unmodified","Pass plain String paths to XPath"],"tags":["antlr","xpath","defensive","java"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}