I have a Document object initialized in the init() method of the servlet and use it in the doPost() method to service the requests.
selectNodeList() xpath query gives exception when the servlet services many request at same time.
The Exception is shown below:
Caused by: javax.xml.transform.TransformerException: -1
at org.apache.xpath.XPath.execute(XPath.java:331)
at org.apache.xpath.CachedXPathAPI.eval(CachedXPathAPI.java:328)
at org.apache.xpath.CachedXPathAPI.selectNodeList(CachedXPathAPI.java:255)
at org.apache.xpath.CachedXPathAPI.selectNodeList(CachedXPathAPI.java:235)
at com.pro.bb.servlets.Controller.getDataOrPeriodForReport(Controller.java:511)
... 23 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
at org.apache.xpath.XPathContext.pushCurrentNode(XPathContext.java:808)
at org.apache.xpath.axes.PredicatedNodeTest.acceptNode(PredicatedNodeTest.java:447)
at org.apache.xpath.axes.AxesWalker.nextNode(AxesWalker.java:409)
at org.apache.xpath.axes.WalkingIterator.nextNode(WalkingIterator.java:176)
at org.apache.xpath.axes.NodeSequence.nextNode(NodeSequence.java:320)
at org.apache.xpath.axes.NodeSequence.runTo(NodeSequence.java:474)
at org.apache.xpath.axes.NodeSequence.setRoot(NodeSequence.java:257)
at org.apache.xpath.axes.LocPathIterator.execute(LocPathIterator.java:257)
at org.apache.xpath.XPath.execute(XPath.java:308)
Help me sort out the issue.
The
CachedXPathAPIclass is not thread-safe. If you’re using it in the servlet, you have to manualy take care for synchonizing access (or use multiple instances).From the Apache Xalan-j javadoc: