You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "xcorpio (GitHub)" <gi...@apache.org> on 2019/09/25 10:49:27 UTC
[GitHub] [dubbo] xcorpio opened issue #5114: ReferenceConfig 中的 interfaceClass 赋值两次
- [x] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
- [x] I have checked the [FAQ](https://github.com/apache/dubbo/blob/master/FAQ.md) of this repository and believe that this is not a duplicate.
### Environment
* Dubbo version: 2.6.5
* Java version: 1.8
### 问题
我在做一个压测工具, 只有 `Interface`,在线编译源码,然后reload 所以自己实现了个`Classloader`。我调用 `setInterface` 后,在 `ReferenceConfig.get()` 时,class 应该是被重新, `interfaceClass = Class.forName(interfaceName, true, Thread.currentThread().getContextClassLoader())` 啦,在那个类加载器里面 找不到我 动态编译的代码, 我觉得 如果 检查下 `interfaceClass` 不为空时,就别 `Class.forName` 啦, 你们觉得呢。
### 现状
`ReferenceConfig` 中的 [interfaceClass](https://github.com/apache/dubbo/blob/master/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java#L128) 属性在两个地方被赋值。
我的代码是直接使用 `ReferenceConfig` 点对点调用的.
1. 我先调用 `setInterface(Class<?> interfaceClass)`
https://github.com/apache/dubbo/blob/master/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java#L568
这个地方 `this.interfaceClass = interfaceClass; 赋值
```java
public void setInterface(Class<?> interfaceClass) {
if (interfaceClass != null && !interfaceClass.isInterface()) {
throw new IllegalStateException("The interface class " + interfaceClass + " is not a interface!");
}
this.interfaceClass = interfaceClass;
setInterface(interfaceClass == null ? null : interfaceClass.getName());
}
```
2. 然后调 `ReferenceConfig.get()` 时, get() -> init()
2.6.5 的代码
```java
private void init() {
...
if (ProtocolUtils.isGeneric(getGeneric())) {
interfaceClass = GenericService.class;
} else {
try {
interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
.getContextClassLoader());
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e.getMessage(), e);
}
checkInterfaceAndMethods(interfaceClass, methods);
}
```
这个地方,好像没检查`interfaceClass`是否为 null, 又重新赋值了下 `interfaceClass = Class.forName(interfaceName, true, Thread.currentThread().getContextClassLoader());`
我看下下 master 上的, https://github.com/apache/dubbo/blob/master/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java#L231
好像还是这样.
[ Full content available at: https://github.com/apache/dubbo/issues/5114 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [dubbo] xcorpio commented on issue #5114: ReferenceConfig 中的 interfaceClass 赋值两次
Posted by "xcorpio (GitHub)" <gi...@apache.org>.
哦,我自己改了`CustomReferenceConfig`, `Thread.currentThread().setContextClassLoader(interfaceClass.getClassLoader());` 就可以啦
[ Full content available at: https://github.com/apache/dubbo/issues/5114 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [dubbo] xcorpio commented on issue #5114: ReferenceConfig 中的 interfaceClass 赋值两次
Posted by "xcorpio (GitHub)" <gi...@apache.org>.
我写了个继承`ReferenceConfig`的类,在 `get()` 时如果 `interfaceClass` 存在就不在 `Class.forName`啦, 但是又报了这个
```
java.lang.IllegalArgumentException: interface pea.dubbo.api.GreetingService is not visible from class loader
at com.alibaba.dubbo.common.bytecode.Proxy.getProxy(Proxy.java:96)
at com.alibaba.dubbo.common.bytecode.Proxy.getProxy(Proxy.java:69)
at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:35)
at com.alibaba.dubbo.rpc.proxy.AbstractProxyFactory.getProxy(AbstractProxyFactory.java:64)
at com.alibaba.dubbo.rpc.proxy.AbstractProxyFactory.getProxy(AbstractProxyFactory.java:34)
at com.alibaba.dubbo.rpc.proxy.wrapper.StubProxyFactoryWrapper.getProxy(StubProxyFactoryWrapper.java:65)
at com.alibaba.dubbo.rpc.ProxyFactory$Adaptive.getProxy(ProxyFactory$Adaptive.java)
```
啊,有啥解决办法吗
[ Full content available at: https://github.com/apache/dubbo/issues/5114 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
[GitHub] [dubbo] xcorpio closed issue #5114: ReferenceConfig 中的 interfaceClass 赋值两次
Posted by "xcorpio (GitHub)" <gi...@apache.org>.
[ issue closed by xcorpio ]
[ Full content available at: https://github.com/apache/dubbo/issues/5114 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org