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( UnresolvedType.java:749):
So I placed a conditional breakpoint there, started up the application, and waited.Code:// check if someone is calling us with something that is a signature already assert name.charAt(0) != '[';
When the breakpoint was hit, the "name" variable had a value of "[Lorg.springframework.core.io.Resource;". 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 "[Lorg.springframework.core.io.Resource;", 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( ):
At this point, the "bean" parameter is an array of Resources.Code: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; }
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):
"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.Code:<property name="mappingLocations"> <bean factory-bean="resourcePopulatingFactory" factory-method="getMappingLocationResources" /> </property>
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?
Thoughts?


Reply With Quote