Skip to content

Commit

Permalink
Fixed RarHandler - non-absolute URL to File conversion
Browse files Browse the repository at this point in the history
- As the Archive#getURI says, the method can return nearly anything and there
  no guarantee that the URI can be converted to a File.
- Sometimes it is an absolute file, sometimes relative path, sometimes URI
  pointing to a file inside jar inside ear.
- This minimalistic fix avoids an exception, similar is on other places.

Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Nov 24, 2024
1 parent a0b2c0d commit 8b3e0ae
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -150,7 +150,7 @@ private boolean isEmbedded(DeploymentContext context) {
public List<URI> getClassPathURIs(ReadableArchive archive) {
List<URI> uris = super.getClassPathURIs(archive);
try {
File archiveFile = new File(archive.getURI());
File archiveFile = toFile(archive.getURI());
if (archiveFile.exists() && archiveFile.isDirectory()) {
// add top level jars
uris.addAll(ASClassLoaderUtil.getLibDirectoryJarURIs(archiveFile));
Expand All @@ -160,4 +160,13 @@ public List<URI> getClassPathURIs(ReadableArchive archive) {
}
return uris;
}


private static File toFile(URI uri) {
try {
return new File(uri.getSchemeSpecificPart());
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Cannot convert URI to file: " + uri, e);
}
}
}

0 comments on commit 8b3e0ae

Please sign in to comment.