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:
      [EMAIL PROTECTED]"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)





Reply via email to