aspose file tools*
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
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
Author

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 "com.philips.sc.impulse.util.xml.XMLHelper" is our own proprietery class file

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

Joined: Oct 14, 2005
Posts: 18991
    
    8

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.ArrayIndexOutOfBoundException: -1 error while using selectNodeList(contextNode,string)