ArrayIndexOutOfBoundsException in SecurityAssociation
milx Oct 10, 2005 7:27 AMHello
I just upgraded from 3.2.7 to 4.0.3, and I see that the org.jboss.SecurityAssociation class is throwing java.lang.ArrayIndexOutOfBoundsException for no particular reason I can think of.
The error occurs when I create new home interfaces for my stateless EJBs, but it's not consistent, as most times the EJBs are created successfully. The error occurs with multiple different EJBs, and causes an insufficient method permissions error with principalRoles=null to be reported back to the client. I took a look at the source, and I see that the exception occurs in the pop() method of the inner class RunAsThreadLocalStack in SecurityAssociation:
RunAsIdentity pop() { ArrayList stack = (ArrayList) local.get(); RunAsIdentity runAs = null; int lastIndex = stack.size() - 1; // This is where the exception occurs if (lastIndex >= 0) runAs = (RunAsIdentity) stack.remove(lastIndex); return runAs; }
Could the cause be unsynchronized access to the ArrayList stack? It looks to me like the size of the List has changed between stack.size() and stack.remove(). Here is an excerpt of the stacktrace:
java.lang.IndexOutOfBoundsException: Index: 72, Size: 72 at java.util.ArrayList.RangeCheck(ArrayList.java:547) at java.util.ArrayList.remove(ArrayList.java:390) at org.jboss.security.SecurityAssociation$RunAsThreadLocalStack.pop(SecurityAssociation.java:623) at org.jboss.security.SecurityAssociation.popRunAsIdentity(SecurityAssociation.java:544) at org.jboss.ejb.plugins.SecurityActions$10.pop(SecurityActions.java:156) at org.jboss.ejb.plugins.SecurityActions.popRunAsIdentity(SecurityActions.java:313) at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:135) at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:121) at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:93) at org.jboss.ejb.SessionContainer.internalInvokeHome(SessionContainer.java:613) at org.jboss.ejb.Container.invoke(Container.java:894) at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invokeHome(BaseLocalProxyFactory.java:344) at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:118) at $Proxy215.create(Unknown Source)
Which causes this error:
Insufficient method permissions, principal=pensum.dk, ejbName=BookAuthorService, method=create, interface=LOCALHOME, requiredRoles=[Staff, User, Customer, Admin], principalRoles=null
The errors occur quite frequently, but are not caught in my (single threaded) test cases. Any help is greatly appreciated.