Decode URL.getPath before resolving a real file

URL with spaces are URL-Encoded and need to be decoded before
they can be used to open files etc.
This commit is contained in:
Simon Willnauer 2015-06-30 11:15:55 +02:00
parent 4102e263df
commit d1a29a63d2
1 changed files with 3 additions and 2 deletions

View File

@ -25,6 +25,7 @@ import org.elasticsearch.common.io.PathUtils;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.nio.file.FileVisitResult; import java.nio.file.FileVisitResult;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -55,12 +56,12 @@ class JarHell {
final Map<String,URL> clazzes = new HashMap<>(32768); final Map<String,URL> clazzes = new HashMap<>(32768);
Set<String> seenJars = new HashSet<>(); Set<String> seenJars = new HashSet<>();
for (final URL url : ((URLClassLoader)loader).getURLs()) { for (final URL url : ((URLClassLoader)loader).getURLs()) {
String path = url.getPath(); String path = URLDecoder.decode(url.getPath(), "UTF-8");
if (path.endsWith(".jar")) { if (path.endsWith(".jar")) {
if (!seenJars.add(path)) { if (!seenJars.add(path)) {
continue; // we can't fail because of sheistiness with joda-time continue; // we can't fail because of sheistiness with joda-time
} }
try (JarFile file = new JarFile(url.getPath())) { try (JarFile file = new JarFile(path)) {
Manifest manifest = file.getManifest(); Manifest manifest = file.getManifest();
if (manifest != null) { if (manifest != null) {
// inspect Manifest: give a nice error if jar requires a newer java version // inspect Manifest: give a nice error if jar requires a newer java version