Skip to content

[core] Disable Caching in URLConnection for ClasspathClassLoader - #4949

Merged
jsotuyod merged 3 commits into
pmd:masterfrom
adangel:issue-4899-jar-closed
Apr 11, 2024
Merged

jsotuyod merged 3 commits into
pmd:masterfrom
adangel:issue-4899-jar-closed

Conversation

@adangel

@adangel adangel commented Apr 11, 2024

Copy link
Copy Markdown
Member

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
@ghost

ghost commented Apr 11, 2024

Copy link
Copy Markdown
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
Copy Markdown
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…

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

2 participants