Search in sources :

Example 26 with ServiceConfigurationError

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");
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) ServiceConfigurationError(java.util.ServiceConfigurationError) IOException(java.io.IOException) URL(java.net.URL) Test(org.junit.Test)

Example 27 with ServiceConfigurationError

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 ");
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) ServiceConfigurationError(java.util.ServiceConfigurationError) Test(org.junit.Test)

Example 28 with ServiceConfigurationError

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);
    }
}
Also used : ServiceConfigurationError(java.util.ServiceConfigurationError)

Example 29 with ServiceConfigurationError

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);
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) LoggerFactory(org.slf4j.LoggerFactory) ServiceConfigurationError(java.util.ServiceConfigurationError) LinkedList(java.util.LinkedList)

Example 30 with ServiceConfigurationError

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);
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) ServiceConfigurationError(java.util.ServiceConfigurationError) LinkedList(java.util.LinkedList)

Aggregations

ServiceConfigurationError (java.util.ServiceConfigurationError)95 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)16 Iterator (java.util.Iterator)15 File (java.io.File)10 URL (java.net.URL)10 URLClassLoader (java.net.URLClassLoader)7 ServiceLoader (java.util.ServiceLoader)7 Test (org.junit.Test)7 BufferedReader (java.io.BufferedReader)6 InputStream (java.io.InputStream)6 InputStreamReader (java.io.InputStreamReader)6 NoSuchElementException (java.util.NoSuchElementException)6 CharsetProvider (java.nio.charset.spi.CharsetProvider)5 HashMap (java.util.HashMap)5 FileInputStream (java.io.FileInputStream)4 Path (java.nio.file.Path)4 SQLException (java.sql.SQLException)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4