{"record":{"id":"e33e7cdcc78564a9","repo":"antlr/antlr4","slug":"could-not-read-path-path-e33e7c","errorCode":null,"errorMessage":"Could not read path: ${path}","messagePattern":"Could not read path: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"warning","filePath":"runtime/CSharp/src/Tree/Xpath/XPath.cs","lineNumber":100,"sourceCode":"            // word not operator/separator\n            // word for invert operator\n            this.parser = parser;\n            this.path = path;\n            elements = Split(path);\n        }\n\n        //\t\tSystem.out.println(Arrays.toString(elements));\n        // TODO: check for invalid token/rule names, bad syntax\n        public virtual XPathElement[] Split(string path)\n        {\n            AntlrInputStream @in;\n            try\n            {\n                @in = new AntlrInputStream(new StringReader(path));\n            }\n            catch (IOException ioe)\n            {\n                throw new ArgumentException(\"Could not read path: \" + path, ioe);\n            }\n            XPathLexer lexer = new _XPathLexer_87(@in);\n            lexer.RemoveErrorListeners();\n            lexer.AddErrorListener(new XPathLexerErrorListener());\n            CommonTokenStream tokenStream = new CommonTokenStream(lexer);\n            try\n            {\n                tokenStream.Fill();\n            }\n            catch (LexerNoViableAltException e)\n            {\n                int pos = lexer.Column;\n                string msg = \"Invalid tokens or characters at index \" + pos + \" in path '\" + path + \"'\";\n                throw new ArgumentException(msg, e);\n            }\n            IList<IToken> tokens = tokenStream.GetTokens();\n            //\t\tSystem.out.println(\"path=\"+path+\"=>\"+tokens);\n            IList<XPathElement> elements = new List<XPathElement>();","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/CSharp/src/Tree/Xpath/XPath.cs#L82-L118","documentation":"XPath.Split wraps an IOException raised while creating the AntlrInputStream over the path string and rethrows it as ArgumentException. In the C# port the input is a StringReader over an in-memory string, so this exception path is effectively unreachable in practice — but it is kept for Java parity. Seeing it means reader construction threw unexpectedly (custom environment/stream issue).","triggerScenarios":"Constructing new XPath(parser, path) where the internal StringReader over the path string throws IOException — theoretically only from exotic runtime failures; in normal C# usage never thrown.","commonSituations":"Essentially none in the C# runtime; would only surface if the runtime violates StringReader's contract or a modified port reads from a real I/O source.","solutions":["Treat this as an environment anomaly: check the path string for correctness and retry with a plain literal XPath.","If you maintain a custom port where the input comes from a file/stream, move to a real file-reading step with its own error handling before constructing XPath.","Report to the runtime maintainers if reproducible, since the stock StringReader path cannot throw."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (path == null) throw new ArgumentNullException(nameof(path)); // path itself must be sane; the IOException branch is otherwise unreachable in the C# port","typeGuard":null,"tryCatchPattern":"try { var xp = new XPath(parser, path); } catch (ArgumentException ex) when (ex.Message.StartsWith(\"Could not read path\")) { /* environment anomaly: log path and inner IOException, retry with a literal */ }","preventionTips":["Treat this branch as unreachable in stock C# usage; a hit indicates a modified runtime or environment problem.","Keep the XPath path a plain in-memory string rather than wiring I/O into construction."],"tags":["antlr","csharp","xpath","io","unreachable"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}