You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "waykingjava (GitHub)" <gi...@apache.org> on 2019/09/30 03:26:45 UTC

[GitHub] [dubbo] waykingjava opened issue #5131: 对动态修改后的类不能正常创建wrapper类

dubbo在调用org.apache.dubbo.common.bytecode.Wrapper#makeWrapper方法创建wrapper时,如果当前class是被动态修改过的比如增加了属性和对应get/set 方法(我们这里的场景是使用javaagent对指定类进行增加了get/set方法),那么makeWrapper方法在使用javassist进行创建类时会对创建的方法进行编译,dubbo生成的invoker方法中会有w.setX((Object) $4[0]); 而setX方法是被动态修改后增加到class中的,这里javassist进行编译时w当然还是原始class文件引用,所以不存在setX方法,故编译不通过。
### Environment

* Dubbo version: 2.7.3
* Operating System version: any
* Java version: 1.8

### Steps to reproduce this issue
1.  duboo暴露aService为provider
2.  引入的javaagent中动态修改aService增加属性dynamicField和对应get/set方法
### Expected Result

对被动态修改过的类也能正常创建wrapper类,
这里是否可以给出设置点,来指定创建wrapper时忽略类对应名称方法。

### Actual Result
dubbo对应暴露服务的类进行生成wrapper类,如果服务类已经被javassist或其他方式动态修改后重新加载到jvm,在创建wrapper调用javassist编译创建的方法时抛出异常。

```
compile error: setDynamicField(java.lang.Object) not found in com.*.*ServiceImpl
	at javassist.compiler.TypeChecker.atMethodCallCore(TypeChecker.java:749)
	at javassist.compiler.TypeChecker.atCallExpr(TypeChecker.java:695)
	at javassist.compiler.JvstTypeChecker.atCallExpr(JvstTypeChecker.java:157)
	at javassist.compiler.ast.CallExpr.accept(CallExpr.java:46)
	at javassist.compiler.CodeGen.doTypeCheck(CodeGen.java:242)
	at javassist.compiler.CodeGen.atStmnt(CodeGen.java:330)
	at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
	at javassist.compiler.CodeGen.atStmnt(CodeGen.java:351)
	at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
	at javassist.compiler.CodeGen.atIfStmnt(CodeGen.java:398)
	at javassist.compiler.CodeGen.atStmnt(CodeGen.java:355)
	at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
	at javassist.compiler.CodeGen.atStmnt(CodeGen.java:351)
	at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
	at javassist.compiler.CodeGen.atMethodBody(CodeGen.java:292)
	at javassist.compiler.CodeGen.atMethodDecl(CodeGen.java:274)
	at javassist.compiler.ast.MethodDecl.accept(MethodDecl.java:44)
	at javassist.compiler.Javac.compileMethod(Javac.java:169)
	at javassist.compiler.Javac.compile(Javac.java:95)
	at javassist.CtNewMethod.make(CtNewMethod.java:74)
	at javassist.CtNewMethod.make(CtNewMethod.java:45)
	at org.apache.dubbo.common.bytecode.ClassGenerator.toClass(ClassGenerator.java:323)
	at org.apache.dubbo.common.bytecode.ClassGenerator.toClass(ClassGenerator.java:287)
	at org.apache.dubbo.common.bytecode.Wrapper.makeWrapper(Wrapper.java:261)
	at org.apache.dubbo.common.bytecode.Wrapper.getWrapper(Wrapper.java:118)
	at org.apache.dubbo.rpc.proxy.javassist.JavassistProxyFactory.getInvoker(JavassistProxyFactory.java:41)
	at org.apache.dubbo.rpc.proxy.wrapper.StubProxyFactoryWrapper.getInvoker(StubProxyFactoryWrapper.java:118)
	at org.apache.dubbo.rpc.ProxyFactory$Adaptive.getInvoker(ProxyFactory$Adaptive.java)
	at org.apache.dubbo.config.ServiceConfig.exportLocal(ServiceConfig.java:641)
	at org.apache.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:576)
	at org.apache.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:457)
	at org.apache.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:415)
	at org.apache.dubbo.config.ServiceConfig.export(ServiceConfig.java:378)
	at org.apache.dubbo.config.spring.ServiceBean.export(ServiceBean.java:336)
	at org.apache.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:114)
	at org.apache.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:60)
```


[ Full content available at: https://github.com/apache/dubbo/issues/5131 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org