Skip to content

Commit

Permalink
Optimize getExtensionClass method. (#2788)
Browse files Browse the repository at this point in the history
Just return the class instead of throwing exception.
  • Loading branch information
carryxyh authored and ralf0131 committed Dec 6, 2018
1 parent 216e750 commit 628ad77
Showing 1 changed file with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,8 @@ public boolean hasExtension(String name) {
if (name == null || name.length() == 0) {
throw new IllegalArgumentException("Extension name == null");
}
try {
this.getExtensionClass(name);
return true;
} catch (Throwable t) {
return false;
}
Class<?> c = this.getExtensionClass(name);
return c != null;
}

public Set<String> getSupportedExtensions() {
Expand Down Expand Up @@ -565,11 +561,7 @@ private Class<?> getExtensionClass(String name) {
if (name == null) {
throw new IllegalArgumentException("Extension name == null");
}
Class<?> clazz = getExtensionClasses().get(name);
if (clazz == null) {
throw new IllegalStateException("No such extension \"" + name + "\" for " + type.getName() + "!");
}
return clazz;
return getExtensionClasses().get(name);
}

private Map<String, Class<?>> getExtensionClasses() {
Expand Down

0 comments on commit 628ad77

Please sign in to comment.