Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ClassFinder for paths containint '+' #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
Expand Down Expand Up @@ -41,7 +43,7 @@ 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)};
final URL[] urls = {new File(jarPath).toURI().toURL()};
loader = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());
}

Expand Down Expand Up @@ -73,9 +75,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