Search code examples
jbossaopjboss6.x

JBoss 6 AS with AOP throws StackOverflowError


I am using JBoss 6 AS and trying to add via AOP an interceptor to the classes in some package from a deployed application. This is the scenario:

  • I have an app.jar that contains the classes to which I want to add advices. This JAR also has some EJBs (ejb-jar.xml, jboss.xml).
  • I created my on JBoss interceptor like this :

    package util;
    import org.jboss.aop.joinpoint.Invocation;
    import org.jboss.aop.joinpoint.MethodInvocation;
    public class MyInterceptor implements org.jboss.aop.advice.Interceptor {
        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            long startTime = System.currentTimeMillis();
            try {
                return invocation.invokeNext();
            } finally {
                long endTime = System.currentTimeMillis() - startTime;
                System.out.println("MyInterceptor : " + endTime);
                if (invocation instanceof MethodInvocation) {
                    MethodInvocation mi = (MethodInvocation) invocation;
                    String clazz = "";
                    String method = "";
                    try {
                        clazz = mi.getTargetObject().getClass().toString();
                        method = mi.getMethod().getName();
                    } catch (Throwable e) {
                        System.out.println("Error when trying to get target info");
                    }
                    System.out.println("MyInterceptor : " + endTime);
                }
            }
        }
    
        @Override
        public String getName() {
            return "MyInterceptor";
        }
    }
    
  • I created a jboss-aop.xml file that contains:

    <?xml version="1.0" encoding="UTF-8"?>
    <aop xmlns="urn:jboss:aop-beans:1.0">
        <interceptor name="MyInterceptor"  class="util.MyInterceptor"/>
        <bind pointcut="execution(* my.app.*->*(..))">
            <interceptor-ref name="MyInterceptor"/>
        </bind>
    </aop>
    
  • I have set enableLoadTimeWeaving (bootstrap/aop.xml)

  • I have pluggable-instrumentor.jar in the right place (JBOSS/bin)
  • I have started the server with the option -javaagent:pluggable-instrumentor.jar
  • I have created a JAR file interceptor.jar where I put MyInterceptor.class and in its META-INF I've placed the jboss-aop.xml file

Now, that being said, the problem is that when I run my application and some method from any class from my.app package is being called the interceptor seems to intercept the call but it throws a nasty StackOverflowError. This is a part of my error stack:

java.lang.StackOverflowError
at org.jboss.resteasy.core.SynchronousDispatcher.unwrapException(SynchronousDispatcher.java:345) [:6.1.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:321) [:6.1.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:214) [:6.1.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:190) [:6.1.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:534) [:6.1.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:496) [:6.1.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.invokePropagateNotFound(SynchronousDispatcher.java:155) [:6.1.0.Final]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:212) [:6.1.0.Final]
at org.jboss.resteasy.plugins.server.servlet.FilterDispatcher.doFilter(FilterDispatcher.java:59) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.1.0.Final]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [:6.1.0.Final]
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.1.0.Final]
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159) [:6.1.0.Final]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.1.0.Final]
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0.Final]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.1.0.Final]
at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0.Final]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.1.0.Final]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.1.0.Final]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.1.0.Final]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.1.0.Final]
at java.lang.Thread.run(Thread.java:745) [:1.7.0_79]
Caused by: java.lang.StackOverflowError
at my.app.JoinPoint_invoke_N_5164114663869737738_3.invokeJoinpoint(JoinPoint_invoke_N_5164114663869737738_3.java) [:]
at my.app.MyInterceptor$MyInterceptorAdvisor.invoke_N_5164114663869737738(MyInterceptor$MyInterceptorAdvisor.java) [:]
at my.app.MyInterceptor.invoke(MyInterceptor.java) [:]
at my.app.JoinPoint_invoke_N_5164114663869737738_3.invokeNext(JoinPoint_invoke_N_5164114663869737738_3.java) [:]
at my.app.JoinPoint_invoke_N_5164114663869737738_3.invokeJoinpoint(JoinPoint_invoke_N_5164114663869737738_3.java) [:]
at my.app.MyInterceptor$MyInterceptorAdvisor.invoke_N_5164114663869737738(MyInterceptor$MyInterceptorAdvisor.java) [:]
at my.app.MyInterceptor.invoke(MyInterceptor.java) [:]

Basically what happens is that these four lines are being thrown until StackOverflowError gets raised:

at my.app.JoinPoint_invoke_N_5164114663869737738_3.invokeNext(JoinPoint_invoke_N_5164114663869737738_3.java) [:]
at my.app.JoinPoint_invoke_N_5164114663869737738_3.invokeJoinpoint(JoinPoint_invoke_N_5164114663869737738_3.java) [:]
at my.app.MyInterceptor$MyInterceptorAdvisor.invoke_N_5164114663869737738(MyInterceptor$MyInterceptorAdvisor.java) [:]
at my.app.MyInterceptor.invoke(MyInterceptor.java) [:]

If anyone had some similar problem any help would be appeciated!


Solution

  • Well i found the problem ... i put the interceptor on the same package my.app and not in util ... so eventually it was calling itself endlessly until the stack was full . So ... my bad