Repository navigation
[core] Disable Caching in URLConnection for ClasspathClassLoader - #4949
Merged
Merged
Conversation
Generated by 🚫 Danger |
This was referenced Apr 11, 2024
jsotuyod
reviewed
Apr 11, 2024
| // Uses a pseudo URL to be able to call URLConnection#setDefaultUseCaches | ||
| // with Java9+ there is a static method for that per protocol: | ||
| // https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/net/URLConnection.html#setDefaultUseCaches(java.lang.String,boolean) | ||
| URI.create("jar:file:file.jar!/").toURL().openConnection().setDefaultUseCaches(false); |
Member
There was a problem hiding this comment.
I find it a little disturbing that there is very little documentation as to what openConnection() does or when it may throw an IOException. For HTTP/HTTPS it's explicitly stated that no connection is open until connect() is invoked, but for files I've found nothing at all…
We are effectively relying on openConnection() not checking or touching the file for this to work…
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.
Describe the PR
That's the easiest solution I came up with - just disabling the cache for Jar Files.
I'm not sure about the memory/performance consequences. In case this is bad, we probably need to write our own "URLClassLoader" that caches Jarfiles not globally but only within our ClasspathClassLoader instance.
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)