Skip to content
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

Could not generate CGLIB subclass of class io.lettuce.core.support.ConnectionPoolSupport$1 #843

Closed
peerit12 opened this issue Sep 7, 2018 · 8 comments
Labels
status: declined A suggestion or change that we dont feel we should currently apply

Comments

@peerit12
Copy link

peerit12 commented Sep 7, 2018

Bug Report

Current Behavior

I am current using lettuce for the redis cache implementation.

Input Code

Tried to use connection pooling support for redis connection

but got this exception

Unable to register MBean [clusterConnection] with key 'clusterConnection'; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class io.lettuce.core.support.ConnectionPoolSupport$1: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null

GenericObjectPool<StatefulRedisClusterConnection<String, Object>> pool = ConnectionPoolSupport
.createGenericObjectPool(()->clusterClient.connect(new SerializedObjectCodec()),genericPollConfig );

I was using this code for creating connection poll.

Please suggest some solution

@mp911de
Copy link
Collaborator

mp911de commented Sep 7, 2018

What are you trying to achieve and why do you want to subclass an anonymous inner class?

@mp911de mp911de added status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage labels Sep 7, 2018
@peerit12
Copy link
Author

peerit12 commented Sep 7, 2018

I am trying to create connection pool for redis connection.For creating connection pool I am using ConnectionPoolSupport of lettuce-core

I want my GenericObjectPool to store pool of
StatefulRedisClusterConnection<String, Object>

want to get StatefulRedisClusterConnection Object from this pool.

ERROR  org.springframework.boot.SpringApplication.reportFailure - Application run failed
org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [clusterConnection] with key 'clusterConnection'; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class io.lettuce.core.support.ConnectionPoolSupport$1: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
	at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:625) ~[spring-context-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.jmx.export.MBeanExporter.lambda$registerBeans$2(MBeanExporter.java:551) ~[spring-context-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.jmx.export.MBeanExporter$$Lambda$934/663716901.accept(Unknown Source) ~[na:na]
	at java.util.HashMap.forEach(HashMap.java:1280) ~[na:1.8.0_45]
	at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:551) ~[spring-context-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.jmx.export.MBeanExporter.afterSingletonsInstantiated(MBeanExporter.java:434) ~[spring-context-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:777) ~[spring-beans-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
	at com.franconnect.multitenant.SkyTenantsConfigApplication.main(SkyTenantsConfigApplication.java:55) [classes!/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45]
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [fcsky-common-multitenant-config-0.0.1.jar:na]
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [fcsky-common-multitenant-config-0.0.1.jar:na]
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [fcsky-common-multitenant-config-0.0.1.jar:na]
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [fcsky-common-multitenant-config-0.0.1.jar:na]
Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class io.lettuce.core.support.ConnectionPoolSupport$1: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
	at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:208) ~[spring-aop-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110) ~[spring-aop-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.jmx.export.MBeanExporter.registerLazyInit(MBeanExporter.java:708) ~[spring-context-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:596) ~[spring-context-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	... 23 common frames omitted
Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
	at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:345) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:492) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_45]
	at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:480) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:337) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:58) ~[spring-aop-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:205) ~[spring-aop-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	... 26 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
	at sun.reflect.GeneratedMethodAccessor53.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45]
	at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:459) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:336) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
	... 39 common frames omitted
Caused by: java.lang.VerifyError: Cannot inherit from final class
	at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_45]
	at java.lang.ClassLoader.defineClass(ClassLoader.java:760) ~[na:1.8.0_45]
	... 44 common frames omitted

@mp911de
Copy link
Collaborator

mp911de commented Sep 9, 2018

I'm not sure we can do something about this issue here. Care to post your boot config? Currently, we cannot see why Spring is trying to create a proxy around ConnectionPoolSupport$1

ConnectionPoolSupport$1 is not defined final, according to

RedisClient client = RedisClient.create();

GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport
		.createGenericObjectPool(client::connect, new GenericObjectPoolConfig());

System.out.println(Modifier.isFinal(pool.getClass().getModifiers()));

@peerit12
Copy link
Author

So how do i proceed further please suggest any solution.
I am currently using SpringBoot springBootVersion = '2.0.3.RELEASE'
if any other information you need then please let me know

@mp911de
Copy link
Collaborator

mp911de commented Sep 10, 2018

Please provide a project that is able to reproduce the issue (Ideally using start.spring.io). Currently, we cannot see why Spring is trying to create a proxy around ConnectionPoolSupport$1?

@peerit12
Copy link
Author

redis-sample.zip

I have uploaded my project . please use redis host in application.properties
when you try to run this application then shows the same error

@mp911de
Copy link
Collaborator

mp911de commented Sep 10, 2018

Thanks a lot. Proxying happens because RedisCacheFactory is marked as @Lazy. Moving @Bean methods into a different type removes the necessity for proxying. The pool itself isn't required to be lazy. You can control this aspect with minIdle on the pool.

Proxying GenericObjectPool isn't the best idea as you run into two consequences:

  • Enabling JMX will expose the proxy and the actual pool instance as JMX beans. The latter is fine, the former is an artifact of proxying.
  • Some methods in GenericObjectPool are final and will produce a huge number of warnings in your log.

@mp911de
Copy link
Collaborator

mp911de commented Sep 17, 2018

Closing this one as we cannot do anything further here.

@mp911de mp911de closed this as completed Sep 17, 2018
@mp911de mp911de added status: declined A suggestion or change that we dont feel we should currently apply and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage labels Sep 17, 2018
mp911de added a commit that referenced this issue Jan 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we dont feel we should currently apply
Projects
None yet
Development

No branches or pull requests

2 participants