Two Laptop Bag*
The moose likes XML and Related Technologies and the fly likes java.lang.ArrayIndexOutOfBoundException: -1 error while using selectNodeList(contextNode,string) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "java.lang.ArrayIndexOutOfBoundException: -1 error while using selectNodeList(contextNode,string)" Watch "java.lang.ArrayIndexOutOfBoundException: -1 error while using selectNodeList(contextNode,string)" New topic

java.lang.ArrayIndexOutOfBoundException: -1 error while using selectNodeList(contextNode,string)

Hemanth Kumar Simhadri
Ranch Hand

Joined: Apr 22, 2010
Posts: 32
Hello Guyz,

we have implemented the XML parsing using the Apache XML API (xalan.jar) in our web application and in the production environment.

Some times when load on the server is heavy we are getting the "ArrayIndexOutOfBoundException -1" error messages during the XML parsing process and this is leading to the severe server problems. The error messages are appeared when huge number of users are accessing the application at the same time and number of instances are accessing the "selectNodeList(contextnode, string)" method of CachedXPathAPI" class.

Upon rigorous investigation I am able to reproduce this error in a sample java program in Eclipse.

I designed the java program very similar to our program in the application and tested it in the ecilipse. To replicate the scenario I implemented multi threading and created 100 threads and accessed the method selectNodeList(contextNode,string) simultaniously.

The error is as below

This error is not reproducible always. similarly in our production environment also we are getting this message when server load is heavy.

My sample program is as below:

The XML file content has this data

The class "" is our own proprietery class file

How to solve this problem. Can anybody help us here please...
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

It looks to me like the CachedXPathAPI object is not thread-safe. Have you tried synchronizing access to it?
Hemanth Kumar Simhadri
Ranch Hand

Joined: Apr 22, 2010
Posts: 32
Hi Paul,

You are correct. It was mentioned in the CachedXPathAPI class API that :

"Any particular instance of CachedXPathAPI must not be operated upon by multiple threads without synchronization."

The methods of CachedXPathAPI class are not thread safe. By synchronizing the code it worked fine for any number of threads. The execution is always successful

The code should be as below. This is working good

I have to try implementing the same in our production server and let you know the result
It is sorta covered in the JavaRanch Style Guide.
subject: java.lang.ArrayIndexOutOfBoundException: -1 error while using selectNodeList(contextNode,string)
Similar Threads
Reading one line from a text
Need suggestions for improving the performance of the Tomcat server in production environment
Replacing a word in a text file
to read lines inside brackets
Text to speech