Handle relative URLs in jar's Class-Path when getting changeable URLs

5e0ba6ea added support for reading a jar manifest's Class-Path
attribute when resolving changeable URLs from a URLClassLoader,
however it did not handle relative URLs, i.e. URLs without a protocol,
correctly.

This commit updates ChangeableUrls so that it uses the URL of the
JAR that contains the manifest as the base for any new URLs that
are created. When the Class-Path entry is relative, this base will
be used. When the Class-Path entry is absolutee, URL's constructor
will ignore the supplied base.

Closes gh-5665
This commit is contained in:
Andy Wilkinson
2016-04-12 13:47:58 +01:00
parent af2483816b
commit 1412eaa0e0
2 changed files with 8 additions and 6 deletions

View File

@@ -94,7 +94,7 @@ final class ChangeableUrls implements Iterable<URL> {
JarFile jarFile = getJarFileIfPossible(url);
if (jarFile != null) {
try {
return getUrlsFromClassPathAttribute(jarFile.getManifest());
return getUrlsFromClassPathAttribute(url, jarFile.getManifest());
}
catch (IOException ex) {
throw new IllegalStateException(
@@ -118,7 +118,7 @@ final class ChangeableUrls implements Iterable<URL> {
return null;
}
private static List<URL> getUrlsFromClassPathAttribute(Manifest manifest) {
private static List<URL> getUrlsFromClassPathAttribute(URL base, Manifest manifest) {
List<URL> urls = new ArrayList<URL>();
String classPathAttribute = manifest.getMainAttributes()
.getValue(Attributes.Name.CLASS_PATH);
@@ -126,7 +126,7 @@ final class ChangeableUrls implements Iterable<URL> {
for (String entry : StringUtils.delimitedListToStringArray(classPathAttribute,
" ")) {
try {
urls.add(new URL(entry));
urls.add(new URL(base, entry));
}
catch (MalformedURLException ex) {
throw new IllegalStateException(