Announcement Announcement Module
Collapse
No announcement yet.
Strange exceptions with AbstractAspectjJpaTests Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Strange exceptions with AbstractAspectjJpaTests

    I have a test, UserServiceTest, that extends AbstractAspectjJpaTests -- it works perfectly.

    Now I create a subclass of AbstractAspectjJpaTests:

    Code:
    public abstract class IntegrationAspectjJpaTestCase extends AbstractAspectjJpaTests {
        @Override
        protected String[] getConfigLocations() {
            return new String[] { 
                    "META-INF/itest-server.ctx.xml" 
            };
        }    
    }
    
    public class UserServiceTest extends IntegrationAspectjJpaTestCase {
        ... 
    }
    This yields dozens of the following exceptions (note, the test still pass):

    Code:
    java.lang.NullPointerException
    	at org.aspectj.weaver.bcel.BcelWeaver.weaveParentTypeMungers(BcelWeaver.java:1353)
    	at org.aspectj.weaver.bcel.BcelWeaver.weaveParentsFor(BcelWeaver.java:1223)
    	at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1058)
    	at org.aspectj.weaver.tools.WeavingAdaptor.getWovenBytes(WeavingAdaptor.java:279)
    	at org.aspectj.weaver.tools.WeavingAdaptor.weaveClass(WeavingAdaptor.java:212)
    	at org.aspectj.weaver.loadtime.Aj.preProcess(Aj.java:65)
    	at org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter.transform(ClassPreProcessorAgentAdapter.java:55)
    	at org.springframework.instrument.classloading.ShadowingClassLoader.applyTransformers(ShadowingClassLoader.java:119)
    	at org.springframework.instrument.classloading.ShadowingClassLoader.doLoadClass(ShadowingClassLoader.java:101)
    	at org.springframework.instrument.classloading.ShadowingClassLoader.loadClass(ShadowingClassLoader.java:58)
    	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Unknown Source)
    	at org.aspectj.weaver.loadtime.Options.parse(Options.java:66)
    	at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.registerOptions(ClassLoaderWeavingAdaptor.java:209)
    	at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.registerDefinitions(ClassLoaderWeavingAdaptor.java:178)
    	at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.initialize(ClassLoaderWeavingAdaptor.java:123)
    	at org.aspectj.weaver.loadtime.Aj$ExplicitlyInitializedClassLoaderWeavingAdaptor.initialize(Aj.java:130)
    	at org.aspectj.weaver.loadtime.Aj$ExplicitlyInitializedClassLoaderWeavingAdaptor.getWeavingAdaptor(Aj.java:135)
    	at org.aspectj.weaver.loadtime.Aj$WeaverContainer.getWeaver(Aj.java:101)
    	at org.aspectj.weaver.loadtime.Aj.preProcess(Aj.java:61)
    	at org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter.transform(ClassPreProcessorAgentAdapter.java:55)
    	at org.springframework.instrument.classloading.ShadowingClassLoader.applyTransformers(ShadowingClassLoader.java:119)
    	at org.springframework.instrument.classloading.ShadowingClassLoader.doLoadClass(ShadowingClassLoader.java:101)
    	at org.springframework.instrument.classloading.ShadowingClassLoader.loadClass(ShadowingClassLoader.java:58)
    	at org.apache.commons.logging.impl.LogFactoryImpl$1.run(LogFactoryImpl.java:441)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.apache.commons.logging.impl.LogFactoryImpl.loadClass(LogFactoryImpl.java:435)
    	at org.apache.commons.logging.impl.LogFactoryImpl.isLog4JAvailable(LogFactoryImpl.java:505)
    	at org.apache.commons.logging.impl.LogFactoryImpl.getLogClassName(LogFactoryImpl.java:327)
    	at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:368)
    	at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
    	at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
    	at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
    	at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
    	at org.springframework.util.FileCopyUtils.<clinit>(FileCopyUtils.java:49)
    	at org.springframework.instrument.classloading.ShadowingClassLoader.doLoadClass(ShadowingClassLoader.java:100)
    	at org.springframework.instrument.classloading.ShadowingClassLoader.loadClass(ShadowingClassLoader.java:58)
    	at org.springframework.test.jpa.AbstractJpaTests.runBare(AbstractJpaTests.java:175)
    	at junit.framework.TestResult$1.protect(TestResult.java:110)
    	at junit.framework.TestResult.runProtected(TestResult.java:128)
    	at junit.framework.TestResult.run(TestResult.java:113)
    	at junit.framework.TestCase.run(TestCase.java:120)
    	at junit.framework.TestSuite.runTest(TestSuite.java:228)
    	at junit.framework.TestSuite.run(TestSuite.java:223)
    	at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    I can move the method getConfigLocations() from IntegrationAspectjJpaTestCase to UserServiceTest and get the same results. What is the magic that allows only the spring impl of AbstractJpaTests?

  • #2
    Another clue: I hacked the following class as an experiment to move the aspectj weaving up the abstract test hierarchy -- tests run with this as the base also yield the same exceptions:

    Code:
    public abstract class IntegrationAspectjDependencyInjectionSpringContextTestCase extends AbstractDependencyInjectionSpringContextTests {
    
        // ...all variables and methods hacked from other spring abstract 
        // required to get runBare() to compile test 
    
        @Override
        public void runBare() throws Throwable {
            // .. exactly what is in AbstractJpaTests
        }
    
        private static class LoadTimeWeaverInjectingBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter { 
            // just a copy
        }
    
        private static class ShadowingLoadTimeWeaver implements LoadTimeWeaver {
            // just a copy
        }
    }

    Comment


    • #3
      Ok, I found the cause, but I have no idea why. I define an aspectj IMessage handler and install it in aop.xml. If I remove the "-XmessageHandlerClass:" then I don't get these exceptions.

      I don't really see how subclassing AbstractAspectjJpaTests could have any impact on this?

      Code:
      <aspectj>
      	<weaver 
              options="-verbose -showWeaveInfo -XmessageHandlerClass:org.opentrader.runtime.aspectj.AspectJWeaverLogger">
                  ...
              </weaver>
              ...
      </aspectj>
      Code:
      public class AspectJWeaverLogger implements IMessageHandler{
      
          static {
              try {
                  Log4jConfigurer.initLogging("classpath:log4j.properties");
              } catch (FileNotFoundException e) {
                  throw new RuntimeException(e);
              }
          }
          
          private final Logger logger = Logger.getLogger(this.getClass());
          
          public boolean handleMessage(IMessage message) throws AbortException {
              
              Kind messageKind = message.getKind();
      
              if (logger.isDebugEnabled() || logger.isTraceEnabled()) {
                  if (messageKind == IMessage.DEBUG) {
                      logger.debug(makeMessageFor(message));
                      return true;
                  }
              } 
              
              if (logger.isInfoEnabled()) {
                  if ((messageKind == IMessage.INFO) || (messageKind == IMessage.WEAVEINFO)) {
                      logger.info(makeMessageFor(message));
                      return true;
                  }
              } 
              
              if (messageKind == IMessage.WARNING) {
                  logger.warn(makeMessageFor(message));
                  return true;
              }
              
              if (messageKind == IMessage.ERROR) {
                  logger.error(makeMessageFor(message));
                  return true;
              }
              
              if (messageKind == IMessage.ABORT) {
                  logger.fatal(makeMessageFor(message));
                  return true;
              }
              
              return false;
          }
          
          private String makeMessageFor(IMessage message) {
              return message.getMessage();
          }
      
          public boolean isIgnoring(Kind messageKind) {
              return false;
          }
      
          public void dontIgnore(Kind messageKind) {
              // we weren't ignoring anything anyway...
          }
      
      }

      Comment

      Working...
      X