This is an automated email from the git hooks/post-receive script. New commit to branch feature/155_ClassCastException_in_I18nStore_init in repository i18n. See https://gitlab.nuiton.org/nuiton/i18n.git commit c1ac9f8cc6f1066e25cf362d8859840d3b322825 Author: Arnaud Thimel <thimel@codelutin.com> Date: Fri Jan 3 16:31:57 2020 +0100 Improve code style --- .../src/main/java/org/nuiton/i18n/I18nUtil.java | 41 ++++++++++++---------- 1 file changed, 23 insertions(+), 18 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 c39f2f5..6540382 100644 --- a/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java +++ b/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java @@ -35,6 +35,7 @@ import java.io.File; import java.io.IOException; import java.lang.reflect.Method; import java.net.MalformedURLException; +import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; @@ -48,12 +49,12 @@ import java.util.Arrays; import java.util.Enumeration; import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.Optional; import java.util.Stack; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; -import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.zip.ZipFile; @@ -281,35 +282,28 @@ public class I18nUtil { return Optional.of(result); } else { try { - Enumeration<URL> urls = ClassLoader.getSystemResources(""); List<URL> classpathUris = new ArrayList<>(); - for (; urls.hasMoreElements(); ) { + Enumeration<URL> urls = ClassLoader.getSystemResources(""); + while (urls.hasMoreElements()) { try (Stream<Path> walk = Files.walk(Paths.get(urls.nextElement().toURI()))) { - List<URL> result = walk.filter(Files::isRegularFile) - .map(Path::toUri).map(uri -> { - try { - return uri.toURL(); - } catch (MalformedURLException e) { - if (log.isWarnEnabled()) { - log.warn("An error occured while walking through classpath, it may not work as expected",e); - } - return null; - } - }).collect(Collectors.toList()); - - classpathUris.addAll(result); + walk.filter(Files::isRegularFile) + .map(Path::toUri) + .map(I18nUtil::safeUriToUrlOrNull) + .filter(Objects::nonNull) + .forEach(classpathUris::add); } catch (IOException | URISyntaxException | FileSystemNotFoundException e) { if (log.isWarnEnabled()) { - log.warn("An error occured while walking through classpath, it may not work as expected",e); + log.warn("An error occurred while walking through classpath, it may not work as expected", e); } } } - return Optional.of(classpathUris.toArray(new URL[0])); + URL[] result = classpathUris.toArray(new URL[0]); + return Optional.of(result); } catch (IOException e) { if (log.isWarnEnabled()) { log.warn("An error occured while walking through classpath, it may not work as expected",e); @@ -320,6 +314,17 @@ public class I18nUtil { } } + private static URL safeUriToUrlOrNull(URI uri) { + try { + return uri.toURL(); + } catch (MalformedURLException e) { + if (log.isWarnEnabled()) { + log.warn("An error occured while walking through classpath, it may not work as expected",e); + } + return null; + } + } + /** * Returns the all urls to be used in a {@link URLClassLoader}. * -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.