<div dir="ltr"><div dir="ltr">On Sun, Feb 22, 2026 at 3:43 PM Alan Bateman <<a href="mailto:alan.bateman@oracle.com">alan.bateman@oracle.com</a>> wrote:</div><div class="gmail_quote gmail_quote_container"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
On 22/02/2026 14:29, Eirik Bjørsnøs wrote:<br>
> :<br>
><br>
> 1) getResourceAsStream calls HEAD before calling GET. I don't quite <br>
> understand why this is necessary, it seems it would be better to do <br>
> the GET unconditionally to save a request.<br>
><br>
I don't know if URLClassLoader is used much these days for remote class <br>
loading but it may be that getResourceAsStream is using getResource to <br>
get a URL to the resource, then it opens a connection.</blockquote><div><br></div><div>Indeed, getResourceAsStream does call getResource to find the URL object, which triggers the HEAD verification.</div><div><br></div><div>It seems we have the following choices:</div><div><br></div><div>0: Do nothing, HTTP URLs is not used much in URLClassPath</div><div><br></div><div>1: Teach Loader::findResource to return the resolved HttpURLConnection target URL after following a redirect, instead of the original URL. This would allow the GET request in getResourceAsStream to go directly to GET on the redirect location, skipping the first GET. The change would be small and look like:</div><div><br></div><div><font face="monospace">diff --git a/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java b/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java<br>--- a/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java (revision 68c0239618f36aaec2b390a28bccb1fddca421ba)<br>+++ b/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java (date 1771772721240)<br>@@ -534,6 +534,8 @@<br> hconn.setRequestMethod("HEAD");<br> if (hconn.getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {<br> return null;<br>+ } else {<br>+ return hconn.getURL();<br> }<br> } else {<br> // our best guess for the other cases</font><br></div><div><br></div><div>2: Teach getResourceAsStream to find resources without doing GET first. This would be a more involved change, since the "finding" algorithm would need to involve GET instead of the current HEAD. Probably more risk than reward.</div><div><br></div><div>Cheers,</div><div>Eirik.</div></div></div>