-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[ISSUE#12022] Fix nacos datasource plugin ClassCastException bug (#12… #12031
Conversation
@@ -43,7 +43,15 @@ public class MapperProxy implements InvocationHandler { | |||
|
|||
public <R> R createProxy(Mapper mapper) { | |||
this.mapper = mapper; | |||
return (R) Proxy.newProxyInstance(MapperProxy.class.getClassLoader(), mapper.getClass().getInterfaces(), this); | |||
Class<?> clazz = mapper.getClass(); | |||
while (clazz.getInterfaces().length == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个逻辑是否也有风险? 现在这个实现的逻辑是找到第一个interfaces不为0的类/或父类, 如果插件实现的时候自己定义了一个接口,然后那个接口也不是Mapper的子类或接口,应该也会出现ClassCase异常。
看下是否把所有的这个传入的mapper的所有interface都获取出来,然后让Proxy代理上?
如果没必要的话, 只需要找到实现了Mapper的对应class,然后再获取这个类的interfaces来动态代理。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确实,这点是我考虑不周了,如果插件在实现的时候有自己的接口,这里也会报错。
拿实现了Mapper的对应class的interfaces,目前看来足够使用了,nacos中调用findMapper()也用不到插件自己实现的接口。
CI seems can't pass, please check and fix them |
What is the purpose of the change
Fix nacos datasource plugin ClassCastException bug https://github.com/alibaba/nacos/issues/12022
Brief changelog
Modify the clazz.getInterfaces() method in com.alibaba.nacos.plugin.datasource.proxy.MapperProxy#createProxy so that clazz can obtain the correct Class<?>[] interface
Verifying this change
After repair, nacos can run normally without ClassCastException and does not affect the original mysql mapper.
postgersql:
mysql: