Make URLJarCollector tolerant of JDK 21 (and newer JVMs)#90
Merged
Conversation
flemming-n-larsen
approved these changes
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This change hardens the static initializer in
robocode.core/src/main/java/net/sf/robocode/io/URLJarCollector.javaso Robocoderuns correctly on JDK 21 and other modern JVMs where the internal
sun.net.www.protocol.jar.*layout differs from the classic Sun/Oracle JVM.Problem
URLJarCollectorreflects into the JDK-internal classessun.net.www.protocol.jar.JarFileFactoryandsun.net.www.protocol.jar.JarURLConnectionto enable a fast, caching JARconnection path. On JDK 21:
RuntimeException(e.g.InaccessibleObjectExceptionfrom the module system),which was not caught by the previous
catchclause.fileCache/urlCachemay not be in the shapethe caching path assumes.
Because the previous code only caught the checked reflection exceptions
(
ClassNotFoundException | NoSuchFieldException | IllegalAccessException), anyRuntimeExceptionthrown during initialization escaped thestaticblock andprevented the class from loading.
Fix
sunJVM = true) only when bothfileCacheandurlCachewere successfully resolved to non-null values,rather than assuming success after the reflection calls.
RuntimeExceptionso unexpected failures (such as the module-systemaccess errors seen on JDK 21) gracefully fall back to the non-caching code path
instead of failing class initialization.
When the JVM is not recognized,
openConnectionsimply disables URL caching(
urlConnection.setUseCaches(false)), which is the correct, portable behavior.