You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Tahura Chaudhry <ta...@hotmail.com> on 2005/01/29 00:35:35 UTC
invalid XPath syntax leads to RuntimeException
In my application, I provide a UI to allow the user to enter an XPath
expression. I call Xalan's XPathEvaluator.evaluate(....) to determine if
they syntax of the entered expression is valid. If evalute() throws a
DOMException or an XPathException, I assume that the XPath syntax is invalid
and notify the user. I also display the exception string
(exception.getMessage()) to the user in the UI.
This works well for most cases. However I have come across a case in which
entering an invalid syntax leads to a java.lang.RuntimeException.
The XPath expression that causes this is:
EmployeeInfo[@title="manager"] and
I can't assume that the RuntimeException will always be thrown because of
invalid syntax.
Is there a better way to validate the syntax of the XPath expression?
The entire exception trace resulting from calling evalute() on the above
XPath expression is shown below:
[java] java.lang.RuntimeException: Programmer's assertion in
getNextStepPos: unknown stepType:
-1
[java] java.lang.RuntimeException: Programmer's assertion in
getNextStepPos: unknown stepType:
-1
[java] at
org.apache.xpath.compiler.OpMap.getNextStepPos(OpMap.java:278)
[java] at
org.apache.xpath.axes.DescendantIterator.<init>(DescendantIterator.java:119)
[java] at
org.apache.xpath.axes.WalkerFactory.newDTMIterator(WalkerFactory.java:298)
[java] at
org.apache.xpath.compiler.Compiler.locationPath(Compiler.java:670)
[java] at
org.apache.xpath.compiler.Compiler.compile(Compiler.java:210)
[java] at
org.apache.xpath.compiler.Compiler.compileOperation(Compiler.java:248)
[java] at org.apache.xpath.compiler.Compiler.or(Compiler.java:285)
[java] at
org.apache.xpath.compiler.Compiler.compile(Compiler.java:158)
[java] at
org.apache.xpath.compiler.Compiler.compile(Compiler.java:156)
[java] at org.apache.xpath.XPath.<init>(XPath.java:209)
[java] at org.apache.xpath.XPath.<init>(XPath.java:238)
[java] at
org.apache.xpath.domapi.XPathEvaluatorImpl.createExpression(XPathEvaluatorImpl.ja
va:165)
[java] at
org.apache.xpath.domapi.XPathEvaluatorImpl.evaluate(XPathEvaluatorImpl.java:257)
Re: invalid XPath syntax leads to RuntimeException
Posted by Henry Zongaro <zo...@ca.ibm.com>.
Hi, Tahura.
"Tahura Chaudhry" <ta...@hotmail.com> wrote on 2005-01-28 06:35:35 PM:
> In my application, I provide a UI to allow the user to enter an XPath
> expression. I call Xalan's XPathEvaluator.evaluate(....) to determine
if
> they syntax of the entered expression is valid. If evalute() throws a
> DOMException or an XPathException, I assume that the XPath syntax is
invalid
> and notify the user. I also display the exception string
> (exception.getMessage()) to the user in the UI.
>
> This works well for most cases. However I have come across a case in
which
> entering an invalid syntax leads to a java.lang.RuntimeException.
>
> The XPath expression that causes this is:
> EmployeeInfo[@title="manager"] and
>
> I can't assume that the RuntimeException will always be thrown because
of
> invalid syntax.
>
> Is there a better way to validate the syntax of the XPath expression?
>
> The entire exception trace resulting from calling evalute() on the above
> XPath expression is shown below:
>
> [java] java.lang.RuntimeException: Programmer's assertion in
> getNextStepPos: unknown stepType:
> -1
Catching DOMExceptions and XPathExceptions is the correct way to
check for expressions that do not match the XPath syntax or other problems
in evaluating XPath expressions. RuntimeExceptions thrown by Xalan-J
Interpretive while parsing XPath expressions are usually caused by bugs in
the XPath parser. This particular problem was previously reported as
XALANJ-1478.[1]
I'll take a look to see whether I can resolve this bug in parsing
XPath expressions.
Thanks,
Henry
[1] http://issues.apache.org/jira/browse/XALANJ-1478
------------------------------------------------------------------
Henry Zongaro Xalan development
IBM SWS Toronto Lab T/L 969-6044; Phone +1 905 413-6044
mailto:zongaro@ca.ibm.com