Ignoring ArrayIndexOutOfBoundsException message
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jason_Choo
Posted On:   Thursday, January 17, 2008 09:33 PM

I encounter such a problem on a web application. It seems tht the index has exceed the maximum storage limit. How do I resolve it? java.lang.IndexOutOfBoundsException: Index: 4, Size: 4 java.util.ArrayList.RangeCheck(Unknown Source) java.util.ArrayList.get(Unknown Source) com.powerlife.sc.action.UserGroupEnqAction.linkToDetail(UserGroupEnqAction.java:255) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269) org.apach   More>>

I encounter such a problem on a web application. It seems tht the index has exceed the maximum storage limit. How do I resolve it?


java.lang.IndexOutOfBoundsException: Index: 4, Size: 4

java.util.ArrayList.RangeCheck(Unknown Source)
java.util.ArrayList.get(Unknown Source)
com.powerlife.sc.action.UserGroupEnqAction.linkToDetail(UserGroupEnqAction.java:255)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
com.powerlife.sc.action.UserSecurityFilter.doFilter(UserSecurityFilter.java:155)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:211)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:805)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:696)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)
java.lang.Thread.run(Unknown Source)

   <<Less

Re: Ignoring ArrayIndexOutOfBoundsException message

Posted By:   Somasundram_balakrushnan  
Posted On:   Monday, February 18, 2008 04:01 PM

Take a close look at the exception trace - try figuring out any clue of source code you may have used.

From the above trace,May be this is causing the exception:

com.powerlife.sc.action.UserSecurityFilter.doFilter(UserSecurityFilter.java:155)

If you have the source of UserSecurityFilter.java find out what surrounds line: 155. Take a hard-look at the calls that may lead to an Out-of-bounds.

~ Som.

Re: Ignoring ArrayIndexOutOfBoundsException message

Posted By:   Stephen_McConnell  
Posted On:   Saturday, January 19, 2008 07:44 PM

Usually you are going to loop through an Array List to search for items in the ArrayList. As you iterate through the List, you always check the size() method to see if you are out of bounds and just don't issue the call to it.


However, I have had instances where


  1. I didn't know what the index into the array was going to be

  2. Or the array was actually null


Before I tried to get an item out of the array.


There are several ways to handle it.


  1. You can, again, check the index against the size() method of the array BEFORE you try extract the element from the array.

  2. You can put a try/catch block around the access of the array and catch the IndexOutOfBoundsException. You can then do what you want inside the catch block.


I would recommend the FIRST option. Try/catch blocks take up some extra processing time and more code than just doing range checking before you try to extract the element.


Take care


Stephen McConnell

Re: Ignoring ArrayIndexOutOfBoundsException message

Posted By:   Robert_Lybarger  
Posted On:   Thursday, January 17, 2008 09:51 PM

You resolve it by not asking the collection for an index value is does not have... what other sort of answer were you expected?
About | Sitemap | Contact