<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: 2.7.8</li>
<li>Operating System version: macOS Catalina</li>
<li>Java version: 1.8</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<p dir="auto"><code class="notranslate">TreePathDynamicConfiguration#publishConfig</code> will call <code class="notranslate">AbstractDynamicConfiguration.execute()</code> to execute Callable and result type required <code class="notranslate">boolean</code>。execute() will return <code class="notranslate">null</code> when some Exception throw during execute Callable and then NPE will throw. Also <code class="notranslate">AbstractDynamicConfiguration#removeConfig</code> has the same problem.</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    public final boolean publishConfig(String key, String group, String content) {
        String pathKey = buildPathKey(group, key);
       // NPE may occur if execute(...) return null
        return execute(() -&gt; doPublishConfig(pathKey, content), getDefaultTimeout());
    }"><pre class="notranslate">    <span class="pl-k">public</span> <span class="pl-k">final</span> <span class="pl-smi">boolean</span> <span class="pl-s1">publishConfig</span>(<span class="pl-smi">String</span> <span class="pl-s1">key</span>, <span class="pl-smi">String</span> <span class="pl-s1">group</span>, <span class="pl-smi">String</span> <span class="pl-s1">content</span>) {
        <span class="pl-smi">String</span> <span class="pl-s1">pathKey</span> = <span class="pl-en">buildPathKey</span>(<span class="pl-s1">group</span>, <span class="pl-s1">key</span>);
       <span class="pl-c">// NPE may occur if execute(...) return null</span>
        <span class="pl-k">return</span> <span class="pl-en">execute</span>(() -&gt; <span class="pl-en">doPublishConfig</span>(<span class="pl-s1">pathKey</span>, <span class="pl-s1">content</span>), <span class="pl-en">getDefaultTimeout</span>());
    }</pre></div>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    protected final &lt;V&gt; V execute(Callable&lt;V&gt; task, long timeout) {
        V value = null;
        try {
            if (timeout &lt; 1) { // less or equal 0
                value = task.call();
            } else {
                Future&lt;V&gt; future = workersThreadPool.submit(task);
                value = future.get(timeout, TimeUnit.MILLISECONDS);
            }
        } catch (Exception e) {
           // will return null
            if (logger.isErrorEnabled()) {
                logger.error(e.getMessage(), e);
            }
        }
        return value;
    }"><pre class="notranslate">    <span class="pl-k">protected</span> <span class="pl-k">final</span> &lt;<span class="pl-smi">V</span>&gt; <span class="pl-s1">V</span> <span class="pl-en">execute</span>(<span class="pl-s1">Callable</span>&lt;<span class="pl-s1">V</span>&gt; <span class="pl-s1">task</span>, <span class="pl-smi">long</span> <span class="pl-s1">timeout</span>) {
        <span class="pl-smi">V</span> <span class="pl-s1">value</span> = <span class="pl-c1">null</span>;
        <span class="pl-k">try</span> {
            <span class="pl-k">if</span> (<span class="pl-s1">timeout</span> &lt; <span class="pl-c1">1</span>) { <span class="pl-c">// less or equal 0</span>
                <span class="pl-s1">value</span> = <span class="pl-s1">task</span>.<span class="pl-en">call</span>();
            } <span class="pl-k">else</span> {
                <span class="pl-smi">Future</span>&lt;<span class="pl-smi">V</span>&gt; <span class="pl-s1">future</span> = <span class="pl-s1">workersThreadPool</span>.<span class="pl-en">submit</span>(<span class="pl-s1">task</span>);
                <span class="pl-s1">value</span> = <span class="pl-s1">future</span>.<span class="pl-en">get</span>(<span class="pl-s1">timeout</span>, <span class="pl-smi">TimeUnit</span>.<span class="pl-c1">MILLISECONDS</span>);
            }
        } <span class="pl-k">catch</span> (<span class="pl-smi">Exception</span> <span class="pl-s1">e</span>) {
           <span class="pl-c">// will return null</span>
            <span class="pl-k">if</span> (<span class="pl-s1">logger</span>.<span class="pl-en">isErrorEnabled</span>()) {
                <span class="pl-s1">logger</span>.<span class="pl-en">error</span>(<span class="pl-s1">e</span>.<span class="pl-en">getMessage</span>(), <span class="pl-s1">e</span>);
            }
        }
        <span class="pl-k">return</span> <span class="pl-s1">value</span>;
    }</pre></div>
<h3 dir="auto">Expected Result</h3>
<p dir="auto"><code class="notranslate">TreePathDynamicConfiguration#publishConfig</code> return  false when some Exception happened during execute Callable</p>
<h3 dir="auto">Actual Result</h3>
<p dir="auto">throw NPE</p>
<p dir="auto">If there is an exception, please attach the exception trace:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Caused by: org.apache.zookeeper.KeeperException$NoAuthException: KeeperErrorCode = NoAuth for /home/qianqian/dubbo/metadata
	at org.apache.zookeeper.KeeperException.create(KeeperException.java:116)
	at org.apache.zookeeper.KeeperException.create(KeeperException.java:54)
	at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:792)
	at org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1177)
	at org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1158)
	at org.apache.curator.connection.StandardConnectionHandlingPolicy.callWithRetry(StandardConnectionHandlingPolicy.java:64)
	at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:100)
	at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:1155)
	at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:605)
	at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:595)
	at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:573)
	at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:49)
	at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.createPersistent(CuratorZookeeperClient.java:90)
	... 16 common frames omitted
java.lang.NullPointerException: null
	at org.apache.dubbo.common.config.configcenter.TreePathDynamicConfiguration.publishConfig(TreePathDynamicConfiguration.java:90)
	at org.apache.dubbo.metadata.report.support.ConfigCenterBasedMetadataReport.saveMetadata(ConfigCenterBasedMetadataReport.java:123)
	at org.apache.dubbo.metadata.report.support.ConfigCenterBasedMetadataReport.doStoreConsumerMetadata(ConfigCenterBasedMetadataReport.java:67)
	at org.apache.dubbo.metadata.report.support.AbstractMetadataReport.storeConsumerMetadataTask(AbstractMetadataReport.java:309)
	at org.apache.dubbo.metadata.report.support.AbstractMetadataReport.lambda$storeConsumerMetadata$1(AbstractMetadataReport.java:295)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)"><pre class="notranslate"><code class="notranslate">Caused by: org.apache.zookeeper.KeeperException$NoAuthException: KeeperErrorCode = NoAuth for /home/qianqian/dubbo/metadata
	at org.apache.zookeeper.KeeperException.create(KeeperException.java:116)
	at org.apache.zookeeper.KeeperException.create(KeeperException.java:54)
	at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:792)
	at org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1177)
	at org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1158)
	at org.apache.curator.connection.StandardConnectionHandlingPolicy.callWithRetry(StandardConnectionHandlingPolicy.java:64)
	at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:100)
	at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:1155)
	at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:605)
	at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:595)
	at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:573)
	at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:49)
	at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.createPersistent(CuratorZookeeperClient.java:90)
	... 16 common frames omitted
java.lang.NullPointerException: null
	at org.apache.dubbo.common.config.configcenter.TreePathDynamicConfiguration.publishConfig(TreePathDynamicConfiguration.java:90)
	at org.apache.dubbo.metadata.report.support.ConfigCenterBasedMetadataReport.saveMetadata(ConfigCenterBasedMetadataReport.java:123)
	at org.apache.dubbo.metadata.report.support.ConfigCenterBasedMetadataReport.doStoreConsumerMetadata(ConfigCenterBasedMetadataReport.java:67)
	at org.apache.dubbo.metadata.report.support.AbstractMetadataReport.storeConsumerMetadataTask(AbstractMetadataReport.java:309)
	at org.apache.dubbo.metadata.report.support.AbstractMetadataReport.lambda$storeConsumerMetadata$1(AbstractMetadataReport.java:295)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
</code></pre></div>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have searched the <a href="https://github.com/apache/dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have checked the <a href="https://github.com/apache/dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: 所有版本</li>
<li>Operating System version: 所有版本</li>
<li>Java version: 所有版本</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<p dir="auto">1.使用自定义的classloader去加载一个jar。<br>
2.初始化该jar里面的某个类，通过ReferenceConfig生成该类的rpc服务。<br>
3.出现各种ClassNotFound或者生成代理类失败</p>
<p dir="auto">Pls. provide [GitHub address] to reproduce this issue.<br>
<a href="https://github.com/apache/dubbo/blob/master/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Proxy.java">https://github.com/apache/dubbo/blob/master/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Proxy.java</a><br>
和<br>
<a href="https://github.com/apache/dubbo/blob/master/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/ClassGenerator.java">https://github.com/apache/dubbo/blob/master/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/ClassGenerator.java</a></p>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">期望dubbo生成代理类的时候使用Thread.currentThread.getContextClassLoader获得的ClassLoader或者要生成Interface的ClassLoader而不是写死直接使用系统的ClassLoader</p>
<p dir="auto">What do you expected from the above steps？<br>
修改上面两个类的默认ClassLoader获取方式</p>
<h3 dir="auto">Actual Result</h3>
<p dir="auto">return getProxy(ClassHelper.getCallerClassLoader(ics[0]), ics);</p>
<p dir="auto">What actually happens?<br>
生成代理类异常</p>
<p dir="auto">If there is an exception, please attach the exception trace:<br>
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'recommendDynamicService' defined in file [D:\project\project\vivoshop-recommend\recommend-core\target\classes\com\vivo\internet\recommend\core\service\impl\RecommendDynamicServiceImpl.class]: Invocation of init method failed; nested exception is java.lang.RuntimeException: java.lang.IllegalArgumentException: interface com.bbkmobile.iqoo.vivoshop.facade.recommend.ManualRecommendFacade is not visible from class loader<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1631) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE]<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE]<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE]<br>
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE]<br>
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE]<br>
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE]<br>
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE]<br>
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:522) ~[spring-context-4.3.22.RELEASE.jar:4.3.22.RELEASE]<br>
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:496) ~[spring-context-4.3.22.RELEASE.jar:4.3.22.RELEASE]<br>
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:627) ~[spring-context-4.3.22.RELEASE.jar:4.3.22.RELEASE]<br>
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:171) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE]<br>
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE]<br>
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:318) ~[spring-context-4.3.22.RELEASE.jar:4.3.22.RELEASE]<br>
... 29 common frames omitted<br>
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: interface com.bbkmobile.iqoo.vivoshop.facade.recommend.ManualRecommendFacade is not visible from class loader<br>
at com.vivo.internet.recommend.core.service.impl.RecommendDynamicServiceImpl.initAndReplaceDynamicProcessors(RecommendDynamicServiceImpl.java:208) ~[classes/:na]<br>
at com.vivo.internet.recommend.core.service.impl.RecommendDynamicServiceImpl.refreshAllDynamicServices(RecommendDynamicServiceImpl.java:167) ~[classes/:na]<br>
at com.vivo.internet.recommend.core.service.impl.RecommendDynamicServiceImpl.afterPropertiesSet(RecommendDynamicServiceImpl.java:246) ~[classes/:na]<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1689) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE]<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1627) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE]<br>
... 41 common frames omitted<br>
Caused by: java.lang.IllegalArgumentException: interface com.bbkmobile.iqoo.vivoshop.facade.recommend.ManualRecommendFacade is not visible from class loader<br>
at com.alibaba.dubbo.common.bytecode.Proxy.getProxy(Proxy.java:98) ~[dubbo-3.0.7-VIVO.jar:3.0.7-VIVO]<br>
at com.alibaba.dubbo.common.bytecode.Proxy.getProxy(Proxy.java:67) ~[dubbo-3.0.7-VIVO.jar:3.0.7-VIVO]<br>
at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:35) ~[dubbo-3.0.7-VIVO.jar:3.0.7-VIVO]<br>
at com.alibaba.dubbo.rpc.proxy.AbstractProxyFactory.getProxy(AbstractProxyFactory.java:49) ~[dubbo-3.0.7-VIVO.jar:3.0.7-VIVO]<br>
at com.alibaba.dubbo.rpc.proxy.wrapper.StubProxyFactoryWrapper.getProxy(StubProxyFactoryWrapper.java:60) ~[dubbo-3.0.7-VIVO.jar:3.0.7-VIVO]<br>
at com.alibaba.dubbo.rpc.ProxyFactory$Adpative.getProxy(ProxyFactory$Adpative.java) ~[dubbo-3.0.7-VIVO.jar:3.0.7-VIVO]<br>
at com.alibaba.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:438) ~[dubbo-3.0.7-VIVO.jar:3.0.7-VIVO]<br>
at com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:312) ~[dubbo-3.0.7-VIVO.jar:3.0.7-VIVO]<br>
at com.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:141) ~[dubbo-3.0.7-VIVO.jar:3.0.7-VIVO]<br>
at com.vivo.internet.recommend.common.utils.DuuboUtils.getReferenceService(DuuboUtils.java:31) ~[classes/:na]<br>
at com.vivo.internet.recommend.core.service.impl.RecommendDynamicServiceImpl.initAndReplaceDynamicProcessors(RecommendDynamicServiceImpl.java:201) ~[classes/:na]<br>
... 45 common frames omitte</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Just put your stack trace here!
无"><pre class="notranslate"><code class="notranslate">Just put your stack trace here!
无
</code></pre></div>