New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CGLIB code generation failure for cross-@Bean FactoryBean call [SPR-13095] #17686

Closed
spring-issuemaster opened this Issue Jun 3, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Jun 3, 2015

Gabriele Del Prete opened SPR-13095 and commented

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.concurrent.ExecutorService]: Factory method 'casCheckExecutor' threw exception; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.IllegalArgumentException-->Protected method: getDefaultThreadNamePrefix()Ljava/lang/String;
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
	... 67 more
Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.IllegalArgumentException-->Protected method: getDefaultThreadNamePrefix()Ljava/lang/String;
	at org.springframework.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:235)
	at org.springframework.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:220)
	at org.springframework.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:216)
	at org.springframework.cglib.proxy.Enhancer.createUsingReflection(Enhancer.java:643)
	at org.springframework.cglib.proxy.Enhancer.firstInstance(Enhancer.java:538)
	at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:225)
	at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
	at org.springframework.cglib.proxy.Enhancer.create(Enhancer.java:285)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.enhanceFactoryBean(ConfigurationClassEnhancer.java:402)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:295)
	at com.marketnews.scrollers.security.SecurityConfig$$EnhancerBySpringCGLIB$$4d2a9eb1.casCheckExecutorFactoryBean(<generated>)
	at com.marketnews.dbsso.spring.AbstractCASWebSecurityConfigurerAdapter.casCheckExecutor(AbstractCASWebSecurityConfigurerAdapter.java:318)
	at com.marketnews.scrollers.security.SecurityConfig$$EnhancerBySpringCGLIB$$4d2a9eb1.CGLIB$casCheckExecutor$17(<generated>)
	at com.marketnews.scrollers.security.SecurityConfig$$EnhancerBySpringCGLIB$$4d2a9eb1$$FastClassBySpringCGLIB$$433a316a.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
	at com.marketnews.scrollers.security.SecurityConfig$$EnhancerBySpringCGLIB$$4d2a9eb1.casCheckExecutor(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
	... 68 more
Caused by: java.lang.IllegalArgumentException: Protected method: getDefaultThreadNamePrefix()Ljava/lang/String;
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:209)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor$1.intercept(ConfigurationClassEnhancer.java:399)
	at org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean$$EnhancerBySpringCGLIB$$93e65b95.getDefaultThreadNamePrefix(<generated>)
	at org.springframework.util.CustomizableThreadCreator.<init>(CustomizableThreadCreator.java:51)
	at org.springframework.scheduling.concurrent.CustomizableThreadFactory.<init>(CustomizableThreadFactory.java:42)
	at org.springframework.scheduling.concurrent.ExecutorConfigurationSupport.<init>(ExecutorConfigurationSupport.java:45)
	at org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean.<init>(ThreadPoolExecutorFactoryBean.java:53)
	at org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean$$EnhancerBySpringCGLIB$$93e65b95.<init>(<generated>)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at org.springframework.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:228)
	... 89 more

Related code is this:

	@Bean
	public ThreadPoolExecutorFactoryBean casCheckExecutorFactoryBean() throws Exception {
		ThreadPoolExecutorFactoryBean threadPoolExecutorFactoryBean = new ThreadPoolExecutorFactoryBean();
		threadPoolExecutorFactoryBean.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2);
		threadPoolExecutorFactoryBean.setQueueCapacity(Integer.MAX_VALUE);
		threadPoolExecutorFactoryBean.setThreadNamePrefix("casCheckExecutor-");
		return threadPoolExecutorFactoryBean;
	}

	@Bean(name="casCheckExecutor")
	public ExecutorService casCheckExecutor() throws Exception {
		return casCheckExecutorFactoryBean().getObject();
	}

Affects: 4.2 RC1

Issue Links:

  • #17514 ConfigurationClassEnhancer.enhanceFactoryBean is not transparent for method calls other than getObject()

Referenced from: commits 869b0bc, 063a720

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Jun 4, 2015

Juergen Hoeller commented

This is an unfortunate side effect from #17514; we've only been testing this with beans with public methods, apparently. To be fixed for 4.2 RC2.

And while we're at it, ThreadPoolExecutorFactoryBean.getObject() wasn't meant to declare Exception. I'm fixing this as well to make it in sync with other ScheduledExecutorFactoryBean and co.

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Jun 4, 2015

Juergen Hoeller commented

Fixed through creating the enhanced FactoryBean instance before applying the corresponding method interceptor. We're preferably using Objenesis there now in order to avoid constructor side effects completely, analogous to AOP proxy creation in ObjenesisCglibAopProxy.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment