Skip to content

Commit 4e52779

Browse files
committed
Don't prepend resource URLs with '/'
In PR #4281 resource URLs started being prefixed with '/', which results in failures to retrieve the resource in some cases. E.g. quarkusio/quarkus#23604
1 parent 61b6238 commit 4e52779

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Resources.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public static ResourceStorageEntry get(String moduleName, String resourceName) {
141141
private static URL createURL(String moduleName, String resourceName, int index) {
142142
try {
143143
String refPart = index != 0 ? '#' + Integer.toString(index) : "";
144-
return new URL(JavaNetSubstitutions.RESOURCE_PROTOCOL, moduleName, -1, '/' + resourceName + refPart);
144+
return new URL(JavaNetSubstitutions.RESOURCE_PROTOCOL, moduleName, -1, resourceName + refPart);
145145
} catch (MalformedURLException ex) {
146146
throw new IllegalStateException(ex);
147147
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/resources/ResourceURLConnection.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public ResourceURLConnection(URL url) {
4444
super(url);
4545
}
4646

47+
private static String resolveName(String resourceName) {
48+
return resourceName.startsWith("/") ? resourceName.substring(1) : resourceName;
49+
}
50+
4751
@Override
4852
public void connect() {
4953
if (connected) {
@@ -57,7 +61,7 @@ public void connect() {
5761
if (urlPath.isEmpty()) {
5862
throw new IllegalArgumentException("Empty URL path not allowed in " + JavaNetSubstitutions.RESOURCE_PROTOCOL + " URL");
5963
}
60-
String resourceName = urlPath.substring(1);
64+
String resourceName = resolveName(urlPath);
6165
ResourceStorageEntry entry = Resources.get(hostNameOrNull, Resources.toCanonicalForm(resourceName));
6266
if (entry != null) {
6367
List<byte[]> bytes = entry.getData();

0 commit comments

Comments
 (0)