Skip to content

Commit

Permalink
Fix a bug in path handling
Browse files Browse the repository at this point in the history
This patch fixes the convertion from URL to path so that paths containing the '+' character are not converted to ' '.
Without it, picard.jar can't be placed in a path where one directory has a '+' in its name (and that happens on Debian builders)
  • Loading branch information
vdanjean committed Sep 8, 2015
1 parent 187b948 commit 6ba6259
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/java/picard/cmdline/ClassFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
Expand Down Expand Up @@ -63,8 +64,8 @@ public ClassFinder(final File jarFile) throws IOException {
// but the jarPath is remembered so that the iteration over the classpath skips anything other than
// the jarPath.
jarPath = jarFile.getCanonicalPath();
final URL[] urls = {new URL("file", "", jarPath)};
loader = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());
final URL[] urls = {new File(jarPath).toURI().toURL()};
loader = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());
}

/** Convert a filename to a class name by removing '.class' and converting '/'s to '.'s. */
Expand Down Expand Up @@ -95,9 +96,14 @@ public void find(String packageName, final Class<?> parentType) {
while (urls.hasMoreElements()) {
try {
String urlPath = urls.nextElement().getFile();
urlPath = URLDecoder.decode(urlPath, "UTF-8");
if ( urlPath.startsWith("file:") ) {
urlPath = urlPath.substring(5);
// convert URL to URI
// http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4466485
// using URLDecode does not work if urlPath has a '+' character
try {
URI uri = new URI(urlPath);
urlPath = uri.getPath();
} catch (URISyntaxException e) {
log.warn("Cannot convert to URI the " + urlPath + " URL");
}
if (urlPath.indexOf('!') > 0) {
urlPath = urlPath.substring(0, urlPath.indexOf('!'));
Expand Down Expand Up @@ -180,4 +186,4 @@ protected void handleItem(final String name) {
public Set<Class<?>> getClasses() {
return this.classes;
}
}
}

0 comments on commit 6ba6259

Please sign in to comment.