- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Description
Brian Curnow opened SPR-3043 and commented
Currently the extractJarFileURL has logic to handle a MalformedURLException. The problem is that the extra slash (added to fix #7607) is invalid when you're on Unix. On Windows the getFile() method on the URL returns a path like:
C:/sandbox/wl9/domains/distribution/./servers/distribution/tmp/_WL_user/_appsdir_getResources_war/kgkwyw/war/WEB-INF/lib/_wl_cls_gen.jar!/META-INF/persistence.xml
Once the method has applied the rest of the logic (it will actually hit the catch block for MalformedURLException) the string it will use to create the URL is:
file:/C:/sandbox/wl9/domains/distribution/./servers/distribution/tmp/_WL_user/_appsdir_getResources_war/kgkwyw/war/WEB-INF/lib/_wl_cls_gen.jar
The extra slash before C:/ is required to fix the "URL is not hierarchical" error. However, on Unix the getFile() method on the URL returns a path like:
/lcl/data/wls/wls9/corp1/./servers/admin/tmp/_WL_user/getResources/ijrc95/war/WEB-INF/lib/_wl_cls_gen.jar!/META-INF/persistence.xml
And once the method has applied the rest of the logic (this will also hit the catch block for MalformedURLException) the string it will use to create the URL is:
file://lcl/data/wls/wls9/corp1/./servers/admin/tmp/_WL_user/getResources/ijrc95/war/WEB-INF/lib/_wl_cls_gen.jar
Now you get the message "URL has authority component" error.
To fix this, a check should be done on the string to see if it starts with a slash, if it doesn't, add one, if it does just add the "file:".
The corrected method is below:
public static URL extractJarFileURL(URL jarUrl) throws MalformedURLException {
String urlFile = jarUrl.getFile();
int separatorIndex = urlFile.indexOf(JAR_URL_SEPARATOR);
if (separatorIndex != -1) {
String jarFile = urlFile.substring(0, separatorIndex);
try {
return new URL(jarFile);
}
catch (MalformedURLException ex) {
// Probably no protocol in original jar URL, like "jar:C:/mypath/myjar.jar".
// This usually indicates that the jar file resides in the file system.
if (jarFile.startsWith("/")) {
return new URL(FILE_URL_PREFIX + jarFile);
} else {
return new URL(FILE_URL_PREFIX + "/" + jarFile);
}
}
}
else {
return jarUrl;
}
}
Affects: 2.0.2