6 Replies Latest reply on Jun 8, 2006 8:03 PM by ben.wang

    Trouble with aopc compiled class being loaded with a factory

    Jeff Black Newbie

      We have a bean that we aspectize via "@@org.jboss.cache.aop.AopMarker" using JDK1.4 and JBossCache 1.3.0. This class is included in a jar that is bundled in a war file and deployed to WebLogic 8.1.

      We then use a factory class to load this via:

      try {
       clazz = Class.forName(className);
       }
       catch (Exception t) {
       log.fatal("Unable to load '" + key
       + "' implementation class: '" + className + "'" + ": " + t);
       log.fatal("Cause: " + t.getCause());
       t.printStackTrace(System.err);
       }


      However, this always fails with a java.lang.ExceptionInInitializationError whose getCause() is ArrayIndexOutOfBoundsException: 8.

      Decompiling the aspectized class shows that the array in question was created by aopc inside of one of the field interception methods. Commenting out this field in our code just moves the getCause() exception to another field interception method's array.

      As a point of reference, removing the @@ annotaion allows the class to loaded without problem.

      I'm not sure what's going on here and I could use someone else's perspective. This is great stuff and I am eager to get it up and running.

      Thanks, Jeff

        • 1. Re: Trouble with aopc compiled class being loaded with a fac
          Brian Stansberry Master

          This is a total shot in the dark, so please just take it as such:

          Have you tried:

           try {
           ClassLoader cl = Thread.currentThread().getContextClassLoader();
           clazz = cl.loadClass(className);
           }
           catch (Exception t) {
           log.fatal("Unable to load '" + key
           + "' implementation class: '" + className + "'" + ": " + t);
           log.fatal("Cause: " + t.getCause());
           t.printStackTrace(System.err);
           }


          • 2. Re: Trouble with aopc compiled class being loaded with a fac
            Master

            Have you tried to use it outside WL first? I meant try to load the "instrumented" class using your example in a standalone Java program.

            Again, it is also a shot in the dark. :-) But can this be related to the WL classloader?

            • 3. Re: Trouble with aopc compiled class being loaded with a fac
              Jeff Black Newbie

              Thank you for the quick replies. I have removed weblogic from the equation and created the following unit test that gives me the same result.

              Note that I originally posted this to the cache forum, because that is where we are headed, but if need be, I could repost this to the AOP forum. We are using jboss-aop-1.3.5.jar, btw. Also I forgor to mention that we are using compile time annotations and aopc.


              package com.gestalt.dmit.mcsoa.registrar.presence.jbosscache.impl;
              
              /**
               * A class that blah....
               *
               * @@org.jboss.cache.aop.AopMarker
               *
               */
              
              public class JeffImpl {
              
               private long _foo;
               private long _bar;
              
               public JeffImpl(long duration, long expires) {
               _foo = duration;
               _bar= expires;
               }
              }



              package com.gestalt.dmit.mcsoa.registrar.presence;
              
              import com.gestalt.dmit.mcsoa.registrar.presence.jbosscache.impl.*;
              import junit.framework.TestCase;
              
              public class PresenceSubscriptionFactoryTest extends TestCase {
              
               public void testGetJeffInstance() {
              
               try {
              
               JeffImpl jps = new JeffImpl(Long.MAX_VALUE, Long.MIN_VALUE);
              
               assertTrue("JeffImpl came back as incorrect implementation! " + jps.getClass().getName(),
               jps instanceof JeffImpl);
              
               } catch (Exception e) {
               e.printStackTrace();
               }
               }
              }
              


              Which throws the following exception:

              [gcpunit] ------------- Standard Error -----------------
               [gcpunit] java.lang.ArrayIndexOutOfBoundsException: 1
               [gcpunit] at com.gestalt.dmit.mcsoa.registrar.presence.jbosscache.impl.JeffImpl._foo_w_$aop(JeffImpl.java)
               [gcpunit] at com.gestalt.dmit.mcsoa.registrar.presence.jbosscache.impl.JeffImpl.<init>(JeffImpl.java:16)
               [gcpunit] at com.gestalt.dmit.mcsoa.registrar.presence.PresenceSubscriptionFactoryTest.testGetJeffInstance(PresenceSubscriptionFactory
              Test.java:12)
               [gcpunit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
               [gcpunit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
               [gcpunit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               [gcpunit] at java.lang.reflect.Method.invoke(Method.java:324)
               [gcpunit] at junit.framework.TestCase.runTest(TestCase.java:154)
               [gcpunit] at junit.framework.TestCase.runBare(TestCase.java:127)
               [gcpunit] at junit.framework.TestResult$1.protect(TestResult.java:106)
               [gcpunit] at junit.framework.TestResult.runProtected(TestResult.java:124)
               [gcpunit] at junit.framework.TestResult.run(TestResult.java:109)
               [gcpunit] at junit.framework.TestCase.run(TestCase.java:118)
               [gcpunit] at junit.framework.TestSuite.runTest(TestSuite.java:208)
               [gcpunit] at junit.framework.TestSuite.run(TestSuite.java:203)


              This is about the simpliest case I could distill our code down to and I am still baffled.

              • 4. Re: Trouble with aopc compiled class being loaded with a fac
                Master

                I have just tried out a similar test case like yours but still can't reproduce. Can you use load-time instrumentation option to see if the problem is there as well?

                Here is the test case:

                 public void testLoadingClass()
                 {
                 Address addr = new Address();
                 addr.getClass().getName();
                 }
                


                Here is Address class that is under JBossCache testsuite.
                package org.jboss.cache.aop.test;
                
                /**
                 * @@org.jboss.cache.aop.AopMarker
                 */
                public class Address
                {
                 String street = null;
                 String city = null;
                 int zip = 0;
                
                 public String getStreet()
                 {
                 return street;
                 }
                
                 public void setStreet(String street)
                 {
                 this.street = street;
                 }
                
                 public String getCity()
                 {
                 return city;
                 }
                
                 public void setCity(String city)
                 {
                 this.city = city;
                 }
                
                 public int getZip()
                 {
                 return zip;
                 }
                
                 public void setZip(int zip)
                 {
                 this.zip = zip;
                 }
                
                 public String toString()
                 {
                 return "street=" + getStreet() + ", city=" + getCity() + ", zip=" + getZip();
                 }
                }
                


                • 5. Re: Trouble with aopc compiled class being loaded with a fac
                  Jeff Black Newbie

                  Ben and all,

                  Thank you for your reply and sample code. I have discovered the problem. My class had underscores prefixing the all the instance variable names. This will cause the ArrayIndexOutOfBoundsException.

                  I verified the same with the sample class Address below. Change all references of

                  street

                  to
                  _street


                  and you should be able to duplicate the error.

                  I am new to JBoss products, so if you could tell me where to file this issue with JIRA, I will do so with reproduceable steps.

                  • 6. Re: Trouble with aopc compiled class being loaded with a fac
                    Master

                    OK. then this is a bug with JBoss Aop. Please file the bug there and Kabir should be able to take care of it.