use of java.util.ServiceConfigurationError in project auto by google.
the class SimpleServiceLoaderTest method brokenLoader.
@Test
public void brokenLoader() {
ClassLoader loader = new URLClassLoader(new URL[0]) {
@Override
public Enumeration<URL> getResources(String name) throws IOException {
throw new IOException("bang");
}
};
try {
SimpleServiceLoader.load(CharSequence.class, loader);
fail();
} catch (ServiceConfigurationError expected) {
assertThat(expected).hasMessageThat().startsWith("Could not look up");
assertThat(expected).hasCauseThat().hasMessageThat().isEqualTo("bang");
}
}
use of java.util.ServiceConfigurationError in project auto by google.
the class SimpleServiceLoaderTest method classNotFound.
@Test
public void classNotFound() throws Exception {
ClassLoader loader = loaderForJarWithEntries(CharSequence.class.getName(), "this.is.not.a.Class");
try {
SimpleServiceLoader.load(CharSequence.class, loader);
fail();
} catch (ServiceConfigurationError expected) {
assertThat(expected).hasMessageThat().startsWith("Could not load ");
}
}
use of java.util.ServiceConfigurationError in project j2objc by google.
the class SelectorProvider method loadProviderFromProperty.
private static boolean loadProviderFromProperty() {
String cn = System.getProperty("java.nio.channels.spi.SelectorProvider");
if (cn == null)
return false;
try {
Class<?> c = Class.forName(cn, true, ClassLoader.getSystemClassLoader());
provider = (SelectorProvider) c.newInstance();
return true;
} catch (ClassNotFoundException x) {
throw new ServiceConfigurationError(null, x);
} catch (IllegalAccessException x) {
throw new ServiceConfigurationError(null, x);
} catch (InstantiationException x) {
throw new ServiceConfigurationError(null, x);
} catch (SecurityException x) {
throw new ServiceConfigurationError(null, x);
}
}
use of java.util.ServiceConfigurationError in project chunjun by DTStack.
the class FactoryUtil method discoverFactories.
private static List<Factory> discoverFactories(ClassLoader classLoader) {
try {
final List<Factory> result = new LinkedList<>();
ServiceLoader.load(Factory.class, classLoader).iterator().forEachRemaining(result::add);
return result;
} catch (ServiceConfigurationError e) {
LOG.error("Could not load service provider for factories.", e);
throw new TableException("Could not load service provider for factories.", e);
}
}
use of java.util.ServiceConfigurationError in project flink-mirror by flink-ci.
the class TableFactoryService method discoverFactories.
/**
* Searches for factories using Java service providers.
*
* @return all factories in the classpath
*/
private static List<TableFactory> discoverFactories(Optional<ClassLoader> classLoader) {
try {
List<TableFactory> result = new LinkedList<>();
ClassLoader cl = classLoader.orElse(Thread.currentThread().getContextClassLoader());
ServiceLoader.load(TableFactory.class, cl).iterator().forEachRemaining(result::add);
return result;
} catch (ServiceConfigurationError e) {
LOG.error("Could not load service provider for table factories.", e);
throw new TableException("Could not load service provider for table factories.", e);
}
}
Aggregations