branch feature/155_ClassCastException_in_I18nStore_init_on_Java11 created (now d2cdd9b)
This is an automated email from the git hooks/post-receive script. New change to branch feature/155_ClassCastException_in_I18nStore_init_on_Java11 in repository i18n. See https://gitlab.nuiton.org/nuiton/i18n.git at d2cdd9b refs #155 Do not blindly cast ClassLoader to URLClassLoader This branch includes the following new commits: new d2cdd9b refs #155 Do not blindly cast ClassLoader to URLClassLoader The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit d2cdd9bd5f1dc4e1ea0f7d2e6a5e71855922d64a Author: Arnaud Thimel <thimel@codelutin.com> Date: Thu May 16 18:19:22 2019 +0200 refs #155 Do not blindly cast ClassLoader to URLClassLoader -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/155_ClassCastException_in_I18nStore_init_on_Java11 in repository i18n. See https://gitlab.nuiton.org/nuiton/i18n.git commit d2cdd9bd5f1dc4e1ea0f7d2e6a5e71855922d64a Author: Arnaud Thimel <thimel@codelutin.com> Date: Thu May 16 18:19:22 2019 +0200 refs #155 Do not blindly cast ClassLoader to URLClassLoader --- .../src/main/java/org/nuiton/i18n/I18nUtil.java | 27 ++++++++++++++++++++++ .../nuiton/i18n/init/ClassPathI18nInitializer.java | 5 ++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java b/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java index 81b6c68..a5d52dc 100644 --- a/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java +++ b/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java @@ -43,6 +43,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Locale; +import java.util.Optional; import java.util.Stack; import java.util.jar.Attributes; import java.util.jar.JarFile; @@ -255,6 +256,32 @@ public class I18nUtil { } } + /** + * Returns the all URLs to be used in a {@link ClassLoader}. + * + * If the given classloader is an URLClassLoader, will do the same as {@link #getDeepURLs(URLClassLoader)}. + * Otherwise this method will try to find URLs by another way. + * + * @param loader the classloader (if null will use system one) + * @return all the url found in the classloader if applicable + * @see #getDeepURLs(URLClassLoader) + */ + public static Optional<URL[]> tryGetDeepURLs(ClassLoader loader) { + + if (loader instanceof URLClassLoader) { + URLClassLoader urlClassLoader = (URLClassLoader) loader; + URL[] result = getDeepURLs(urlClassLoader); + return Optional.of(result); + } + + if (log.isWarnEnabled()) { + log.warn("ClassLoader is not an URLClassLoader, it may not work as expected: " + loader.getClass().getName()); + } + + Optional<URL[]> empty = Optional.empty(); + return empty; + } + /** * Returns the all urls to be used in a {@link URLClassLoader}. * diff --git a/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java b/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java index 192129f..f2768e8 100644 --- a/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java +++ b/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java @@ -32,7 +32,6 @@ import org.nuiton.i18n.bundle.I18nBundle; import org.nuiton.i18n.bundle.I18nBundleUtil; import java.net.URL; -import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -76,8 +75,8 @@ public class ClassPathI18nInitializer extends I18nInitializer { public URL[] resolvURLs() throws Exception { // on calcule toutes les urls utilisable dans le classloader donnee - URLClassLoader loader = (URLClassLoader) getLoader(); - URL[] deepURLs = I18nUtil.getDeepURLs(loader); + ClassLoader classLoader = getLoader(); + URL[] deepURLs = I18nUtil.tryGetDeepURLs(classLoader).orElse(new URL[0]); List<URL> urlToSeek = new ArrayList<>(Arrays.asList(deepURLs)); // on va maintenant supprimer toutes les urls qui ne respectent pas -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm