- [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 
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to