antlr/antlr4 · error · IllegalArgumentException
Unknowth path element "+el
Error message
Unknowth path element "+el
What it means
After lexing, XPath.split switches on each token's type; the default branch throws IllegalArgumentException ('Unknowth path element ...' — typo is in the ANTLR source) when a token type is neither a separator, token/rule ref, wildcard, nor EOF. With the stock XPathLexer this is unreachable; it guards against lexer/runtime version mismatches or custom lexers.
Source
Thrown at runtime/Java/src/org/antlr/v4/runtime/tree/xpath/XPath.java:146
}
XPathElement pathElement = getXPathElement(next, anywhere);
pathElement.invert = invert;
elements.add(pathElement);
i++;
break;
case XPathLexer.TOKEN_REF :
case XPathLexer.RULE_REF :
case XPathLexer.WILDCARD :
elements.add( getXPathElement(el, false) );
i++;
break;
case Token.EOF :
break loop;
default :
throw new IllegalArgumentException("Unknowth path element "+el);
}
}
return elements.toArray(new XPathElement[0]);
}
/**
* Convert word like {@code *} or {@code ID} or {@code expr} to a path
* element. {@code anywhere} is {@code true} if {@code //} precedes the
* word.
*/
protected XPathElement getXPathElement(Token wordToken, boolean anywhere) {
if ( wordToken.getType()==Token.EOF ) {
throw new IllegalArgumentException("Missing path element at end of path");
}
String word = wordToken.getText();
int ttype = parser.getTokenType(word);
int ruleIndex = parser.getRuleIndex(word);
switch ( wordToken.getType() ) {View on GitHub (pinned to 7d5770395b)
Solutions
- Align antlr4 tool and runtime jar versions on the classpath
- If subclassing XPathLexer, only emit token types the XPath splitter understands
- Run dependency:tree / gradle dependencies to find duplicate antlr4 artifacts
Defensive patterns
Strategy: try-catch
Try / catch
try { xpath.split(path); } catch (IllegalArgumentException e) { /* suspect mixed ANTLR versions; fail fast with context */ } Prevention
- Pin a single antlr4 version across the project
- Check for duplicate antlr4 jars when this appears
When it happens
Trigger: Mixing an XPathLexer (or lexer token types) from a different ANTLR version than the XPath class; subclassing XPathLexer to emit custom token types.
Common situations: Conflicting antlr4 jar versions on the classpath (e.g. tool 4.x with runtime 4.y) so token type constants no longer line up.
Related errors
- Could not read path: "+path
- Invalid tokens or characters at index "+pos+" in path '"+pat
- Missing path element at end of path
- {word} at index {startIndex} isn't a valid token name
- {word} at index {startIndex} isn't a valid rule name
AI-assisted analysis of antlr/antlr4@7d5770395b (2026-08-14).
Data as JSON: /api/errors/0f2cfe34480dad4d.
Report an issue: GitHub.