Prevent Tomcat URL "reflective access" warnings

Update the jar `Handler` class to support a non-reflective fallback
mechanism when possible. The updated code attempts to capture a regular
jar URL before our handler is installed. It can then use that URL as
context when creating the a fallback URL. The JDK jar `Handler` will
be copied from the context URL to the fallback URL.

Without this commit, resolving new Tomcat URLs of the form
`jar:war:file:...` would result in an ugly "Illegal reflective access"
warning.

Fixes gh-18631
This commit is contained in:
Phillip Webb
2020-12-17 17:45:44 -08:00
parent 361198ebba
commit c4e41305d5
9 changed files with 288 additions and 10 deletions

View File

@@ -163,6 +163,7 @@ class HandlerTests {
URLConnection jdkConnection = new URL(null, "jar:file:" + testJar.toURI().toURL() + "!/nested.jar!/",
this.handler).openConnection();
assertThat(jdkConnection).isNotInstanceOf(JarURLConnection.class);
assertThat(jdkConnection.getClass().getName()).endsWith(".JarURLConnection");
}
@Test