Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Disable Caching in URLConnection for ClasspathClassLoader #4949

Merged
merged 3 commits into from
Apr 11, 2024

Conversation

adangel
Copy link
Member

@adangel adangel commented Apr 11, 2024

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?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

@adangel adangel added the a:bug PMD crashes or fails to analyse a file. label Apr 11, 2024
@adangel adangel added this to the 7.1.0 milestone Apr 11, 2024
@pmd-test
Copy link

1 Message
📖 Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Download full report as build artifact

Generated by 🚫 Danger

// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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…

@jsotuyod jsotuyod merged commit c472fdf into pmd:master Apr 11, 2024
3 checks passed
@adangel adangel deleted the issue-4899-jar-closed branch April 12, 2024 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug PMD crashes or fails to analyse a file.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[java] Parsing failed in ParseLock#doParse() java.io.IOException: Stream closed
3 participants