[SPR-16161] bean(nameOfBean) doesn't work with Spring Framework 5.0.1 on AspectJ 1.8.12 Created: 05/Nov/17  Updated: 27/Nov/17  Resolved: 15/Nov/17

Status: Closed
Project: Spring Framework
Component/s: Core:AOP
Affects Version/s: 5.0.1
Fix Version/s: 5.0.2

Type: Bug Priority: Minor
Reporter: Francisco Lozano Assignee: Andy Clement
Resolution: Complete Votes: 0
Labels: regression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Days since last comment: 44 weeks, 2 days ago
Last commented by a User: true
Last updater: St├ęphane Nicoll

 Description   

Trying to upgrade to Spring 5.0.1. I'm using AspectJ 1.8.12 as per the release notes of 5.0.1, even if the issues referred to 1.9 RC.

This aspect worked well with 4.3:

	@Component
	@Aspect
	static class MonitorInterceptor extends PerformanceMonitorInterceptor {

		@Override
		@Pointcut("bean(s3Client)")
		public void auditable() {
		}
	}

static abstract class PerformanceMonitorInterceptor {

	public abstract void auditable();

	@Around("auditable()")
	public final Object audit(final ProceedingJoinPoint pjp) throws Throwable {
		String name = createName(pjp);
		String target = pjp.getSignature().getDeclaringTypeName();
		Logger logger = LoggerFactory.getLogger(target);

		StopWatch stopWatch = new StopWatch(name);
		stopWatch.start(name);
		try {
			return pjp.proceed();
		} finally {
			stopWatch.stop();
			logger.debug(stopWatch.shortSummary());
		}
	}

	private static String createName(ProceedingJoinPoint pjp) {
		MethodSignature signature = (MethodSignature) pjp.getSignature();
		Method method = signature.getMethod();
		return method.getName();
	}
}

But in 5.0.1, I get:

java.lang.IllegalStateException: Failed to load ApplicationContext
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:107)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:242)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'conversionService' defined in class path resource [com/mycompany/storage/server/applicationContext.xml]: Cannot create inner bean 'org.springframework.format.number.NumberFormatAnnotationFormatterFactory#7c729a55' of type [org.springframework.format.number.NumberFormatAnnotationFormatterFactory] while setting bean property 'formatters' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.format.number.NumberFormatAnnotationFormatterFactory#7c729a55' defined in class path resource [com/mycompany/storage/server/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting '(' at character position 0
bean(s3Client)
^

	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:327)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:124)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedSet(BeanDefinitionValueResolver.java:413)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:163)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1607)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1352)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:845)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:246)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
	... 25 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.format.number.NumberFormatAnnotationFormatterFactory#7c729a55' defined in class path resource [com/mycompany/storage/server/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting '(' at character position 0
bean(s3Client)
^

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:591)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:312)
	... 44 more
Caused by: java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting '(' at character position 0
bean(s3Client)
^

	at org.aspectj.weaver.tools.PointcutParser.resolvePointcutExpression(PointcutParser.java:334)
	at org.aspectj.weaver.reflect.InternalUseOnlyPointcutParser.resolvePointcutExpression(InternalUseOnlyPointcutParser.java:36)
	at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getDeclaredPointcuts(Java15ReflectionBasedReferenceTypeDelegate.java:309)
	at org.aspectj.weaver.ReferenceType.getDeclaredPointcuts(ReferenceType.java:884)
	at org.aspectj.weaver.ResolvedType$PointcutGetter.get(ResolvedType.java:243)
	at org.aspectj.weaver.ResolvedType$PointcutGetter.get(ResolvedType.java:241)
	at org.aspectj.weaver.Iterators$4$1.hasNext(Iterators.java:213)
	at org.aspectj.weaver.Iterators$4.hasNext(Iterators.java:230)
	at org.aspectj.weaver.ResolvedType.findPointcut(ResolvedType.java:743)
	at org.aspectj.weaver.patterns.ReferencePointcut.resolveBindings(ReferencePointcut.java:148)
	at org.aspectj.weaver.patterns.Pointcut.resolve(Pointcut.java:189)
	at org.aspectj.weaver.tools.PointcutParser.resolvePointcutExpression(PointcutParser.java:331)
	at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:312)
	at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:226)
	at org.springframework.aop.aspectj.AspectJExpressionPointcut.obtainPointcutExpression(AspectJExpressionPointcut.java:197)
	at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:176)
	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:224)
	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:283)
	at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:315)
	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:124)
	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:93)
	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:74)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:352)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:304)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:438)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1708)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583)
	... 46 more



 Comments   
Comment by Francisco Lozano [ 05/Nov/17 ]

If using aspectJ 1.8.11, it seems to work...

Comment by Francisco Lozano [ 05/Nov/17 ]

using aspectj 1.9.0.RC1 also works ...

Comment by Juergen Hoeller [ 11/Nov/17 ]

Andy Clement, since this issue seems to be limited to AspectJ 1.8.12 in particular... could it be possibly a specific regression there? I'm rather puzzled that it seems to work with both 1.8.11 and 1.9 RC1 but not with 1.8.12 inbetween...

Comment by Andy Clement [ 14/Nov/17 ]

1.8.12 included some performance enhancements for Spring AOP. After release it was discovered one went a bit too far resulting in pointcut parsers sometimes having two underlying 'bean' handlers. If that happens then you get the error above. This was reverted in 1.9.0.RC1 until more thinking could be done and indeed the change isn't in the 1.8 master github now either. A 1.8.13 would behave the same as 1.9.0.RC1 - still a big boost to Spring AOP but without the dangerous change.

Comment by Andy Clement [ 14/Nov/17 ]

If you want to try it out, try 1.8.13.BUILD-SNAPSHOT which is on the snapshot repo.spring.io repository.

Comment by Andy Clement [ 15/Nov/17 ]

AspectJ 1.8.13 has just been sent off to central, hopefully be there in the next few hours. This should fix the issue.

Comment by Juergen Hoeller [ 15/Nov/17 ]

Alright, Andy - thanks to your timely work, I'll consider this as resolved for 5.0.2 then!

Master is upgraded to AspectJ 1.8.13 and 1.9 RC2 now.

Comment by Francisco Lozano [ 16/Nov/17 ]

Regardless of this fix, which version should be considered the right one to use in Spring 5.0? 1.9RC2 or 1.8.13?

Comment by Juergen Hoeller [ 16/Nov/17 ]

We're using 1.9 RC2 for building the spring-aspects module (for JDK 9 build compatibility of the ajc compiler) but keep exposing 1.8.13 for general purposes (in particular for pointcut evaluation). So for common AOP purposes, 1.8.13 is the reference version... even when running on JDK 9.

Comment by Andrei Ivanov [ 17/Nov/17 ]

Andy Clement A bit off topic, but where can the code changes for AspectJ be seen? I've been looking at the log of git://git.eclipse.org/gitroot/aspectj/org.aspectj.git, but I don't too many see changes there.

Comment by Andy Clement [ 17/Nov/17 ]

Andrei Ivanov I need to do some tidying up, I currently have two active branches moving forward ahead of master and I need to switch the Java9 one to be master. Right now the branches are:

RB_V1_8 - the 1.8 release branch where the 1.8.13 work has been done

earlyJava9 - where the java9 work is being done.

I typically view it through github mirror:
https://github.com/eclipse/org.aspectj/branches

Generated at Sun Sep 23 18:30:45 UTC 2018 using JIRA 7.9.2#79002-sha1:3bb15b68ecd99a30eb364c4c1a393359bcad6278.