java.util.ServiceConfigurationError Java Examples

The following examples show how to use java.util.ServiceConfigurationError. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AsynchronousChannelProvider.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static AsynchronousChannelProvider loadProviderAsService() {
    ServiceLoader<AsynchronousChannelProvider> sl =
        ServiceLoader.load(AsynchronousChannelProvider.class,
                           ClassLoader.getSystemClassLoader());
    Iterator<AsynchronousChannelProvider> i = sl.iterator();
    for (;;) {
        try {
            return (i.hasNext()) ? i.next() : null;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
 
Example #2
Source File: AsynchronousChannelProvider.java    From j2objc with Apache License 2.0 6 votes vote down vote up
private static AsynchronousChannelProvider loadProviderAsService() {
    ServiceLoader<AsynchronousChannelProvider> sl =
        ServiceLoader.load(AsynchronousChannelProvider.class,
                           ClassLoader.getSystemClassLoader());
    Iterator<AsynchronousChannelProvider> i = sl.iterator();
    for (;;) {
        try {
            return (i.hasNext()) ? i.next() : null;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
 
Example #3
Source File: FactoryFinder.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static <T> T findServiceProvider(final Class<T> type)
        throws DatatypeConfigurationException
{
    try {
        return AccessController.doPrivileged(new PrivilegedAction<T>() {
            public T run() {
                final ServiceLoader<T> serviceLoader = ServiceLoader.load(type);
                final Iterator<T> iterator = serviceLoader.iterator();
                if (iterator.hasNext()) {
                    return iterator.next();
                } else {
                    return null;
                }
            }
        });
    } catch(ServiceConfigurationError e) {
        final DatatypeConfigurationException error =
                new DatatypeConfigurationException(
                    "Provider for " + type + " cannot be found", e);
        throw error;
    }
}
 
Example #4
Source File: FactoryFinder.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
private static <T> T findServiceProvider(final Class<T> type)
        throws DatatypeConfigurationException
{
    try {
        return AccessController.doPrivileged(new PrivilegedAction<T>() {
            public T run() {
                final ServiceLoader<T> serviceLoader = ServiceLoader.load(type);
                final Iterator<T> iterator = serviceLoader.iterator();
                if (iterator.hasNext()) {
                    return iterator.next();
                } else {
                    return null;
                }
            }
        });
    } catch(ServiceConfigurationError e) {
        final DatatypeConfigurationException error =
                new DatatypeConfigurationException(
                    "Provider for " + type + " cannot be found", e);
        throw error;
    }
}
 
Example #5
Source File: SelectorProvider.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
private static boolean loadProviderAsService() {

        ServiceLoader<SelectorProvider> sl =
            ServiceLoader.load(SelectorProvider.class,
                               ClassLoader.getSystemClassLoader());
        Iterator<SelectorProvider> i = sl.iterator();
        for (;;) {
            try {
                if (!i.hasNext())
                    return false;
                provider = i.next();
                return true;
            } catch (ServiceConfigurationError sce) {
                if (sce.getCause() instanceof SecurityException) {
                    // Ignore the security exception, try the next provider
                    continue;
                }
                throw sce;
            }
        }
    }
 
Example #6
Source File: HttpServerProvider.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean loadProviderAsService() {
    Iterator<HttpServerProvider> i =
        ServiceLoader.load(HttpServerProvider.class,
                           ClassLoader.getSystemClassLoader())
            .iterator();
    for (;;) {
        try {
            if (!i.hasNext())
                return false;
            provider = i.next();
            return true;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
 
Example #7
Source File: AsynchronousChannelProvider.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private static AsynchronousChannelProvider loadProviderAsService() {
    ServiceLoader<AsynchronousChannelProvider> sl =
        ServiceLoader.load(AsynchronousChannelProvider.class,
                           ClassLoader.getSystemClassLoader());
    Iterator<AsynchronousChannelProvider> i = sl.iterator();
    for (;;) {
        try {
            return (i.hasNext()) ? i.next() : null;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
 
Example #8
Source File: FtpClientProvider.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean loadProviderFromProperty() {
    String cm = System.getProperty("sun.net.ftpClientProvider");
    if (cm == null) {
        return false;
    }
    try {
        Class<?> c = Class.forName(cm, true, null);
        provider = (FtpClientProvider) c.newInstance();
        return true;
    } catch (ClassNotFoundException |
             IllegalAccessException |
             InstantiationException |
             SecurityException x) {
        throw new ServiceConfigurationError(x.toString());
    }
}
 
Example #9
Source File: RowSetProvider.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Use the ServiceLoader mechanism to load  the default RowSetFactory
 * @return default RowSetFactory Implementation
 */
static private RowSetFactory loadViaServiceLoader() throws SQLException {
    RowSetFactory theFactory = null;
    try {
        trace("***in loadViaServiceLoader():");
        for (RowSetFactory factory : ServiceLoader.load(javax.sql.rowset.RowSetFactory.class)) {
            trace(" Loading done by the java.util.ServiceLoader :" + factory.getClass().getName());
            theFactory = factory;
            break;
        }
    } catch (ServiceConfigurationError e) {
        throw new SQLException(
                "RowSetFactory: Error locating RowSetFactory using Service "
                + "Loader API: " + e, e);
    }
    return theFactory;

}
 
Example #10
Source File: RowSetProvider.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Use the ServiceLoader mechanism to load  the default RowSetFactory
 * @return default RowSetFactory Implementation
 */
static private RowSetFactory loadViaServiceLoader() throws SQLException {
    RowSetFactory theFactory = null;
    try {
        trace("***in loadViaServiceLoader():");
        for (RowSetFactory factory : ServiceLoader.load(javax.sql.rowset.RowSetFactory.class)) {
            trace(" Loading done by the java.util.ServiceLoader :" + factory.getClass().getName());
            theFactory = factory;
            break;
        }
    } catch (ServiceConfigurationError e) {
        throw new SQLException(
                "RowSetFactory: Error locating RowSetFactory using Service "
                + "Loader API: " + e, e);
    }
    return theFactory;

}
 
Example #11
Source File: SelectorProvider.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean loadProviderAsService() {

        ServiceLoader<SelectorProvider> sl =
            ServiceLoader.load(SelectorProvider.class,
                               ClassLoader.getSystemClassLoader());
        Iterator<SelectorProvider> i = sl.iterator();
        for (;;) {
            try {
                if (!i.hasNext())
                    return false;
                provider = i.next();
                return true;
            } catch (ServiceConfigurationError sce) {
                if (sce.getCause() instanceof SecurityException) {
                    // Ignore the security exception, try the next provider
                    continue;
                }
                throw sce;
            }
        }
    }
 
Example #12
Source File: EntityExtractorService.java    From CLIFF with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public ExtractedEntities extractEntitiesFromSentences(Map[] sentences, boolean manuallyReplaceDemonyms, String langauge){
    ExtractedEntities e = new ExtractedEntities();
    try {
        Iterator<EntityExtractor> extractors = loader.iterator();
        while (extractors != null && extractors.hasNext()) {
            EntityExtractor currentExtractor = extractors.next();
            ExtractedEntities e2 = currentExtractor.extractEntitiesFromSentences(sentences, manuallyReplaceDemonyms, langauge);
            e.merge(e2);
        }
    } catch (ServiceConfigurationError serviceError) {
        e = null;
        serviceError.printStackTrace();
    }
    return e;
}
 
Example #13
Source File: ReporterSetup.java    From flink with Apache License 2.0 6 votes vote down vote up
private static Map<String, MetricReporterFactory> loadAvailableReporterFactories(@Nullable PluginManager pluginManager) {
	final Map<String, MetricReporterFactory> reporterFactories = new HashMap<>(2);
	final Iterator<MetricReporterFactory> factoryIterator = getAllReporterFactories(pluginManager);
	// do not use streams or for-each loops here because they do not allow catching individual ServiceConfigurationErrors
	// such an error might be caused if the META-INF/services contains an entry to a non-existing factory class
	while (factoryIterator.hasNext()) {
		try {
			MetricReporterFactory factory = factoryIterator.next();
			String factoryClassName = factory.getClass().getName();
			MetricReporterFactory existingFactory = reporterFactories.get(factoryClassName);
			if (existingFactory == null) {
				reporterFactories.put(factoryClassName, factory);
				LOG.debug("Found reporter factory {} at {} ",
					factoryClassName,
					new File(factory.getClass().getProtectionDomain().getCodeSource().getLocation().toURI()).getCanonicalPath());
			} else {
				LOG.warn("Multiple implementations of the same reporter were found in 'lib' and/or 'plugins' directories for {}. It is recommended to remove redundant reporter JARs to resolve used versions' ambiguity.", factoryClassName);
			}
		} catch (Exception | ServiceConfigurationError e) {
			LOG.warn("Error while loading reporter factory.", e);
		}
	}

	return Collections.unmodifiableMap(reporterFactories);
}
 
Example #14
Source File: SelectorProvider.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean loadProviderAsService() {

        ServiceLoader<SelectorProvider> sl =
            ServiceLoader.load(SelectorProvider.class,
                               ClassLoader.getSystemClassLoader());
        Iterator<SelectorProvider> i = sl.iterator();
        for (;;) {
            try {
                if (!i.hasNext())
                    return false;
                provider = i.next();
                return true;
            } catch (ServiceConfigurationError sce) {
                if (sce.getCause() instanceof SecurityException) {
                    // Ignore the security exception, try the next provider
                    continue;
                }
                throw sce;
            }
        }
    }
 
Example #15
Source File: AsynchronousChannelProvider.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
private static AsynchronousChannelProvider loadProviderAsService() {
    ServiceLoader<AsynchronousChannelProvider> sl =
        ServiceLoader.load(AsynchronousChannelProvider.class,
                           ClassLoader.getSystemClassLoader());
    Iterator<AsynchronousChannelProvider> i = sl.iterator();
    for (;;) {
        try {
            return (i.hasNext()) ? i.next() : null;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
 
Example #16
Source File: HttpServerProvider.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static boolean loadProviderFromProperty() {
    String cn = System.getProperty("com.sun.net.httpserver.HttpServerProvider");
    if (cn == null)
        return false;
    try {
        Class<?> c = Class.forName(cn, true,
                                   ClassLoader.getSystemClassLoader());
        provider = (HttpServerProvider)c.newInstance();
        return true;
    } catch (ClassNotFoundException |
             IllegalAccessException |
             InstantiationException |
             SecurityException x) {
        throw new ServiceConfigurationError(null, x);
    }
}
 
Example #17
Source File: RowSetProvider.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Use the ServiceLoader mechanism to load  the default RowSetFactory
 * @return default RowSetFactory Implementation
 */
static private RowSetFactory loadViaServiceLoader() throws SQLException {
    RowSetFactory theFactory = null;
    try {
        trace("***in loadViaServiceLoader():");
        for (RowSetFactory factory : ServiceLoader.load(javax.sql.rowset.RowSetFactory.class)) {
            trace(" Loading done by the java.util.ServiceLoader :" + factory.getClass().getName());
            theFactory = factory;
            break;
        }
    } catch (ServiceConfigurationError e) {
        throw new SQLException(
                "RowSetFactory: Error locating RowSetFactory using Service "
                + "Loader API: " + e, e);
    }
    return theFactory;

}
 
Example #18
Source File: FtpClientProvider.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean loadProviderFromProperty() {
    String cm = System.getProperty("sun.net.ftpClientProvider");
    if (cm == null) {
        return false;
    }
    try {
        Class<?> c = Class.forName(cm, true, null);
        provider = (FtpClientProvider) c.newInstance();
        return true;
    } catch (ClassNotFoundException |
             IllegalAccessException |
             InstantiationException |
             SecurityException x) {
        throw new ServiceConfigurationError(x.toString());
    }
}
 
Example #19
Source File: HttpServerProvider.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean loadProviderFromProperty() {
    String cn = System.getProperty("com.sun.net.httpserver.HttpServerProvider");
    if (cn == null)
        return false;
    try {
        Class<?> c = Class.forName(cn, true,
                                   ClassLoader.getSystemClassLoader());
        provider = (HttpServerProvider)c.newInstance();
        return true;
    } catch (ClassNotFoundException |
             IllegalAccessException |
             InstantiationException |
             SecurityException x) {
        throw new ServiceConfigurationError(null, x);
    }
}
 
Example #20
Source File: HttpServerProvider.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean loadProviderFromProperty() {
    String cn = System.getProperty("com.sun.net.httpserver.HttpServerProvider");
    if (cn == null)
        return false;
    try {
        Class<?> c = Class.forName(cn, true,
                                   ClassLoader.getSystemClassLoader());
        provider = (HttpServerProvider)c.newInstance();
        return true;
    } catch (ClassNotFoundException |
             IllegalAccessException |
             InstantiationException |
             SecurityException x) {
        throw new ServiceConfigurationError(null, x);
    }
}
 
Example #21
Source File: JavacProcessingEnvironment.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private boolean needClassLoader(String procNames, Iterable<? extends File> workingpath) {
    if (procNames != null)
        return true;

    URL[] urls = new URL[1];
    for(File pathElement : workingpath) {
        try {
            urls[0] = pathElement.toURI().toURL();
            if (ServiceProxy.hasService(Processor.class, urls))
                return true;
        } catch (MalformedURLException ex) {
            throw new AssertionError(ex);
        }
        catch (ServiceProxy.ServiceConfigurationError e) {
            log.error(Errors.ProcBadConfigFile(e.getLocalizedMessage()));
            return true;
        }
    }

    return false;
}
 
Example #22
Source File: RowSetProvider.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Use the ServiceLoader mechanism to load  the default RowSetFactory
 * @return default RowSetFactory Implementation
 */
static private RowSetFactory loadViaServiceLoader() throws SQLException {
    RowSetFactory theFactory = null;
    try {
        trace("***in loadViaServiceLoader():");
        for (RowSetFactory factory : ServiceLoader.load(javax.sql.rowset.RowSetFactory.class)) {
            trace(" Loading done by the java.util.ServiceLoader :" + factory.getClass().getName());
            theFactory = factory;
            break;
        }
    } catch (ServiceConfigurationError e) {
        throw new SQLException(
                "RowSetFactory: Error locating RowSetFactory using Service "
                + "Loader API: " + e, e);
    }
    return theFactory;

}
 
Example #23
Source File: BadProvidersTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "badfactories",
      expectedExceptions = ServiceConfigurationError.class)
public void testBadFactory(String testName, String ignore) throws Exception {
    Path mods = compileTest(TEST1_MODULE);

    // compile the bad factory
    Path source = BADFACTORIES_DIR.resolve(testName);
    Path output = Files.createTempDirectory(USER_DIR, "tmp");
    boolean compiled = CompilerUtils.compile(source, output);
    assertTrue(compiled);

    // copy the compiled class into the module
    Path classFile = Paths.get("p", "ProviderFactory.class");
    Files.copy(output.resolve(classFile),
               mods.resolve(TEST1_MODULE).resolve(classFile),
               StandardCopyOption.REPLACE_EXISTING);

    // load providers and instantiate each one
    loadProviders(mods, TEST1_MODULE).forEach(Provider::get);
}
 
Example #24
Source File: HttpServerProvider.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean loadProviderAsService() {
    Iterator<HttpServerProvider> i =
        ServiceLoader.load(HttpServerProvider.class,
                           ClassLoader.getSystemClassLoader())
            .iterator();
    for (;;) {
        try {
            if (!i.hasNext())
                return false;
            provider = i.next();
            return true;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
 
Example #25
Source File: HttpServerProvider.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean loadProviderAsService() {
    Iterator<HttpServerProvider> i =
        ServiceLoader.load(HttpServerProvider.class,
                           ClassLoader.getSystemClassLoader())
            .iterator();
    for (;;) {
        try {
            if (!i.hasNext())
                return false;
            provider = i.next();
            return true;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
 
Example #26
Source File: RowSetProvider.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Use the ServiceLoader mechanism to load  the default RowSetFactory
 * @return default RowSetFactory Implementation
 */
static private RowSetFactory loadViaServiceLoader() throws SQLException {
    RowSetFactory theFactory = null;
    try {
        trace("***in loadViaServiceLoader():");
        for (RowSetFactory factory : ServiceLoader.load(javax.sql.rowset.RowSetFactory.class)) {
            trace(" Loading done by the java.util.ServiceLoader :" + factory.getClass().getName());
            theFactory = factory;
            break;
        }
    } catch (ServiceConfigurationError e) {
        throw new SQLException(
                "RowSetFactory: Error locating RowSetFactory using Service "
                + "Loader API: " + e, e);
    }
    return theFactory;

}
 
Example #27
Source File: SelectorProvider.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean loadProviderAsService() {

        ServiceLoader<SelectorProvider> sl =
            ServiceLoader.load(SelectorProvider.class,
                               ClassLoader.getSystemClassLoader());
        Iterator<SelectorProvider> i = sl.iterator();
        for (;;) {
            try {
                if (!i.hasNext())
                    return false;
                provider = i.next();
                return true;
            } catch (ServiceConfigurationError sce) {
                if (sce.getCause() instanceof SecurityException) {
                    // Ignore the security exception, try the next provider
                    continue;
                }
                throw sce;
            }
        }
    }
 
Example #28
Source File: AsynchronousChannelProvider.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static AsynchronousChannelProvider loadProviderAsService() {
    ServiceLoader<AsynchronousChannelProvider> sl =
        ServiceLoader.load(AsynchronousChannelProvider.class,
                           ClassLoader.getSystemClassLoader());
    Iterator<AsynchronousChannelProvider> i = sl.iterator();
    for (;;) {
        try {
            return (i.hasNext()) ? i.next() : null;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
 
Example #29
Source File: AsynchronousChannelProvider.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static AsynchronousChannelProvider loadProviderAsService() {
    ServiceLoader<AsynchronousChannelProvider> sl =
        ServiceLoader.load(AsynchronousChannelProvider.class,
                           ClassLoader.getSystemClassLoader());
    Iterator<AsynchronousChannelProvider> i = sl.iterator();
    for (;;) {
        try {
            return (i.hasNext()) ? i.next() : null;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
 
Example #30
Source File: ServiceLoaderUtils.java    From allure1 with Apache License 2.0 6 votes vote down vote up
/**
 * Check {@link java.util.Iterator#hasNext()} safely.
 *
 * @param iterator specified Iterator to check hasNext
 * @return true if {@link java.util.Iterator#hasNext()} checked successfully, false otherwise.
 */
public static boolean checkHasNextSafely(Iterator iterator) {
    try {
        /* Throw a ServiceConfigurationError if a provider-configuration file violates the specified format,
        or if it names a provider class that cannot be found and instantiated, or if the result of
        instantiating the class is not assignable to the service type, or if any other kind of exception
        or error is thrown as the next provider is located and instantiated.
        @see http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html#iterator()
        */
        return iterator.hasNext();
    } catch (Exception | ServiceConfigurationError e) {
        LOGGER.trace("Can't load some service using Java SPI", e);
        LOGGER.error(e.getMessage());
        return false;
    }
}