diecui1202 closed pull request #2518: #2507: Dubbo 's ExtensionLoader may be
can't find custom Extension
URL: https://github.com/apache/incubator-dubbo/pull/2518
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
index 666abfbaba..fcbb292ec7 100644
---
a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
+++
b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
@@ -21,6 +21,7 @@
import org.apache.dubbo.common.extension.support.ActivateComparator;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.utils.ClassHelper;
import org.apache.dubbo.common.utils.ConcurrentHashSet;
import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.Holder;
@@ -123,7 +124,7 @@ private ExtensionLoader(Class<?> type) {
}
private static ClassLoader findClassLoader() {
- return ExtensionLoader.class.getClassLoader();
+ return ClassHelper.getClassLoader(ExtensionLoader.class);
}
public String getExtensionName(T extensionInstance) {
@@ -970,4 +971,4 @@ public String toString() {
return this.getClass().getName() + "[" + type.getName() + "]";
}
-}
\ No newline at end of file
+}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ClassHelper.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ClassHelper.java
index e38752fcab..d2b3434c29 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ClassHelper.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ClassHelper.java
@@ -85,10 +85,10 @@ public static ClassLoader getCallerClassLoader(Class<?>
caller) {
/**
* get class loader
*
- * @param cls
+ * @param clazz
* @return class loader
*/
- public static ClassLoader getClassLoader(Class<?> cls) {
+ public static ClassLoader getClassLoader(Class<?> clazz) {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
@@ -97,8 +97,18 @@ public static ClassLoader getClassLoader(Class<?> cls) {
}
if (cl == null) {
// No thread context class loader -> use class loader of this
class.
- cl = cls.getClassLoader();
+ cl = clazz.getClassLoader();
+ if (cl == null) {
+ // getClassLoader() returning null indicates the bootstrap
ClassLoader
+ try {
+ cl = ClassLoader.getSystemClassLoader();
+ }
+ catch (Throwable ex) {
+ // Cannot access system ClassLoader - oh well, maybe the
caller can live with null...
+ }
+ }
}
+
return cl;
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]