Announcement Announcement Module
No announcement yet.
AssertionError with AspectJ/Spring AOP ... Is this a bug? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • AssertionError with AspectJ/Spring AOP ... Is this a bug?

    One of our developers has assertions enabled (-ea) on his JVM (I'm not really sure why, but that's beside the point of this topic ATM). We had just upgraded from AspectJ 1.6.9 to 1.6.12 and from Spring 3.0.5 to Spring 3.1.0, and suddenly he started getting assertion errors (which prevented Spring from initializing).

    We were able to bypass this by removing "-ea" from his startup script, and everything appears to be working correctly, but it occurred to me that if an assertion was failing in AspectJ, it probably wasn't a good thing, so I decided to track it down.

    The assertion error was coming from org.aspectj.weaver.UnresolvedType.nameToSignature(

    // check if someone is calling us with something that is a signature already
    assert name.charAt(0) != '[';
    So I placed a conditional breakpoint there, started up the application, and waited.

    When the breakpoint was hit, the "name" variable had a value of "[;". This seemed odd to me, so I traced it back up the stacktrace. The "name" variable is coming from a Class<?> object whose name is actually "[;", which means that it is the Class<?> object for an array of Resources, not the Class<?> object for a Resource. I traced it back up the stacktrace further, and came across org.springframework.aop.framework.autoproxy.Abstra ctAutoProxyCreator.postProcessAfterInitialization( ):

    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    	if (bean != null) {
    		Object cacheKey = getCacheKey(bean.getClass(), beanName);
    		if (!this.earlyProxyReferences.contains(cacheKey)) {
    			return wrapIfNecessary(bean, beanName, cacheKey);
    	return bean;
    At this point, the "bean" parameter is an array of Resources.

    Obviously, something isn't right here, but I'm not sure what the solution is. Am I doing something wrong? Is there a bug in Spring AOP? Is there a bug in AspectJ?

    By the way, if you are curious, here is where the bean is coming from (within the bean definition for a Hibernate SessionFactorBean):

    <property name="mappingLocations">
    	<bean factory-bean="resourcePopulatingFactory" factory-method="getMappingLocationResources" />
    "mappingLocations" expects an array of Resources according to the Spring documentation, and getMappingLocationResources returns an array of Resources. That array of Resources is the ultimate cause of the problem.

    Related question: This is the first time I've seen Java Assertions in production code. It seems odd to me, especially since assertions are off by default without a special JVM parameter. But looking at the code in AspectJ, it seems important, too. So, should we be enabling assertions on all of our JVMs? Or not?


  • #2
    Keep a watch on and to be updated when this issue is fixed. In the meantime, running without -ea is the recommended workaround.