3 Replies Latest reply on Mar 25, 2008 8:42 PM by flavia.rainone

    java.lang.ClassCastException

      Hello,
      I have developed an AOP module to inject sessionBeans on my web module (through annotations). My module is working correctly with JBoss-5.0.0Beta2, Beta3 and Beta4. Now I am testing it on JBoss4.2.2 and I am having a ClassCastException

      java.lang.ClassCastException: com.foo.bar.portal.presentation.DefaultActionBeanContext$portalService_Set
       at org.jboss.aop.advice.com.foo.bar.core.aop.aspects.InjectSessionBeanAspect1.invoke(InjectSessionBeanAspect1.java)
       at com.foo.bar.portal.presentation.DefaultActionBeanContext$portalService_Set.invokeNext(DefaultActionBeanContext$portalService_Set.java)
       at com.foo.bar.portal.presentation.DefaultActionBeanContext.portalService_w_$aop(DefaultActionBeanContext.java)
       at com.foo.bar.portal.presentation.DefaultActionBeanContext.<init>(DefaultActionBeanContext.java:40)
       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
       at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
       at java.lang.Class.newInstance0(Class.java:350)
       at java.lang.Class.newInstance(Class.java:303)
      



      My classes are being aspectized at compile time.
      Here is my Advice:

       public Object get(FieldReadInvocation invocation)
       throws Throwable {
       Field field = invocation.getField();
       String jndiBinding = null;
       try {
       jndiBinding = field.getAnnotation(InjectSessionBean.class).jndiBinding();
       } catch (RuntimeException e) {
       log.error("Error getting JNDI Binding from Annotation.", e);
       return null;
       }
       log.debug("getJndiBinding:" + jndiBinding + " for field:" + field);
      
       Object object = aopHelper.getSessionBean(jndiBinding);
       return object;
       }
      



      Any one has any hint for this problem?
      Thanks in advance.
      Best regards,
      Victor Batista


        • 1. Re: java.lang.ClassCastException
          flavia.rainone

          Hi!

          This is due to a bug that we have found on a previous version of JBoss AOP. This bug is fixed now. Which is the JBoss AOP version you are using on JBoss 4.2.2?

          I think it is an old one. In this case, all you have to do is update the JBoss AOP on your server. Download the newest version from our website and run the ant script located in the jboss-40-install/jboss-aop-jdk50.deployer directory of your download JBoss AOP (notice that you have to remove the current jboss-aop-jdk50.deployer of your 4.2.2. server before doing so.

          If this is not the case, then it might be a bug. In this case, please, try changing the signature of your advice to the form below, and let me know if this solves the problem:

          public Object get(Invocation invocation)


          • 2. Re: java.lang.ClassCastException

            Hi Flavia,
            Thanks for your prompt reply. I made the change you suggested and now it is working fine. My method now looks like:

             public Object get(Invocation invocation) {
             if(invocation instanceof FieldReadInvocation) {
             return _get(((FieldReadInvocation)invocation));
             }
             return null;
             }
            


            where _get is my previous method:
             private Object _get(FieldReadInvocation invocation) ...
            


            I am using AOP which comes bundled with JBoss-4.2.2.

            Thanks.
            Best regards,
            Victor



            • 3. Re: java.lang.ClassCastException
              flavia.rainone

              Hi, Victor

              As I thought, you are using a previous JBoss AOP version, that lacks the fix.

              You will have to either stick with your fix, or you can also upgrade to our CR release, which will allow you to use your advice with the original signature. A third alternative would be editing your pointcut expression, in a way that it matches only field read joinpoints.