The method javax.tools.ToolProvider.getSystemTool(Class clazz, String moduleName, String className) has the following body (JDK 12):
private static <T> T getSystemTool(Class<T> clazz, String moduleName, String className) {
try {
ServiceLoader<T> sl = ServiceLoader.load(clazz, ClassLoader.getSystemClassLoader());
for (Iterator<T> iter = sl.iterator(); iter.hasNext(); ) {
T tool = iter.next();
if (matches(tool, moduleName))
return tool;
}
} catch (ServiceConfigurationError e) {
throw new Error(e);
}
return null;
}
I don't understand the reason why authors used the widest Error class instead of something like throw new ToolProviderError(e)
or even without rethrowing at all? Any rethrow with wide error classes doesn't help to understand what is happened here without digging into the exception chain.