You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2021/02/22 05:31:33 UTC
[dubbo] branch master updated: improve error message of create
extension failure (#7131)
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new 9bb5d9e improve error message of create extension failure (#7131)
9bb5d9e is described below
commit 9bb5d9e10e9a5f97965f12e7ccf085a7ae0a3e9b
Author: gongdewei <ky...@qq.com>
AuthorDate: Sun Feb 21 23:31:16 2021 -0600
improve error message of create extension failure (#7131)
---
.../dubbo/common/extension/ExtensionLoader.java | 36 ++++++++++++----------
.../common/extension/ExtensionLoaderTest.java | 2 +-
2 files changed, 20 insertions(+), 18 deletions(-)
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 922b04a..dc65572 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
@@ -599,26 +599,25 @@ public class ExtensionLoader<T> {
}
private IllegalStateException findException(String name) {
- for (Map.Entry<String, IllegalStateException> entry : exceptions.entrySet()) {
- if (entry.getKey().toLowerCase().contains(name.toLowerCase())) {
- return entry.getValue();
- }
- }
StringBuilder buf = new StringBuilder("No such extension " + type.getName() + " by name " + name);
-
int i = 1;
for (Map.Entry<String, IllegalStateException> entry : exceptions.entrySet()) {
- if (i == 1) {
- buf.append(", possible causes: ");
+ if (entry.getKey().toLowerCase().startsWith(name.toLowerCase())) {
+ if (i == 1) {
+ buf.append(", possible causes: ");
+ }
+ buf.append("\r\n(");
+ buf.append(i++);
+ buf.append(") ");
+ buf.append(entry.getKey());
+ buf.append(":\r\n");
+ buf.append(StringUtils.toString(entry.getValue()));
}
+ }
- buf.append("\r\n(");
- buf.append(i++);
- buf.append(") ");
- buf.append(entry.getKey());
- buf.append(":\r\n");
- buf.append(StringUtils.toString(entry.getValue()));
+ if (i == 1) {
+ buf.append(", no related exception was found, please check whether related SPI module is missing.");
}
return new IllegalStateException(buf.toString());
}
@@ -847,6 +846,7 @@ public class ExtensionLoader<T> {
try {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(resourceURL.openStream(), StandardCharsets.UTF_8))) {
String line;
+ String clazz = null;
while ((line = reader.readLine()) != null) {
final int ci = line.indexOf('#');
if (ci >= 0) {
@@ -859,10 +859,12 @@ public class ExtensionLoader<T> {
int i = line.indexOf('=');
if (i > 0) {
name = line.substring(0, i).trim();
- line = line.substring(i + 1).trim();
+ clazz = line.substring(i + 1).trim();
+ } else {
+ clazz = line;
}
- if (line.length() > 0 && !isExcluded(line, excludedPackages)) {
- loadClass(extensionClasses, resourceURL, Class.forName(line, true, classLoader), name, overridden);
+ if (StringUtils.isNotEmpty(clazz) && !isExcluded(clazz, excludedPackages)) {
+ loadClass(extensionClasses, resourceURL, Class.forName(clazz, true, classLoader), name, overridden);
}
} catch (Throwable t) {
IllegalStateException e = new IllegalStateException("Failed to load extension class (interface: " + type + ", class line: " + line + ") in " + resourceURL + ", cause: " + t.getMessage(), t);
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java
index a1a534a..b861fc0 100644
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java
@@ -374,7 +374,7 @@ public class ExtensionLoaderTest {
fail();
} catch (IllegalStateException expected) {
assertThat(expected.getMessage(), containsString("Failed to load extension class (interface: interface org.apache.dubbo.common.extension.ext7.InitErrorExt"));
- assertThat(expected.getCause(), instanceOf(ExceptionInInitializerError.class));
+ assertThat(expected.getMessage(), containsString("java.lang.ExceptionInInitializerError"));
}
}