Repository navigation
Test the nested jar temp dir cleanup - #9945
Merged
Merged
Conversation
Covers the scenarios from jruby#9928: close() deletes the jars it copied, copying a nested jar doesn't keep the class loader that loaded JRuby alive, and a copy close() can't delete is deleted at exit, along with the temp dir. The last one runs in a child JVM that makes the temp dir read-only, so it needs a file system with POSIX permissions.
This was referenced Oct 29, 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.
Follow-up to #9928, with its test scenarios as unit tests, as you asked in your review. Part of #9781, against
jruby-10.0for the 10.0 LTS line.This adds
JRubyClassLoaderTest, which builds a jar with another jar in it in a temp folder, so there's no binary fixture:closeDeletesCopiedJars: adding the nested jar'sjar:…!/inner.jarURL copies it into the temp dir, andclose()deletes the copy.tempDirDoesNotKeepTheClassLoaderAlive: loadsJRubyClassLoaderin a disposable class loader, copies the nested jar and callsclose(), then checks that the class loader is collected. It setsjruby.ji.nested.jar.tmpdirto a new folder while it runs. The hook was only registered by the JRuby that created the directory, so without that, the test could pass on the old code whenever another test had already createdjruby-<pid>.leftoversAreDeletedAtExit: a child JVM copies the nested jar and callsclose()while the temp dir is read-only, so the copy can't be deleted, as on Windows while the jar is still open. After the child exits, the test checks that the copy and the directory are both gone. It needs POSIX file permissions, so it's skipped on Windows, and also whenclose()can delete the copy anyway, for example when running as root.To check that the tests can fail, I ran them against changed versions of
JRubyClassLoader:JRubyClassLoadertempDirDoesNotKeepTheClassLoaderAlivedeleteOnExitfor a copyclose()can't deleteleftoversAreDeletedAtExitdeleteOnExitfor the temp dirleftoversAreDeletedAtExitcloseDeletesCopiedJarsandleftoversAreDeletedAtExitalso pass with the shutdown hook, which deleted everything too. They check that #9928 kept that behaviour. LikeScriptingContainerClassLeakTest,tempDirDoesNotKeepTheClassLoaderAliverelies onSystem.gc().Native libraries that
DynamicLibraryextracts from a jar aren't covered. That would need a real native library for each platform../mvnw -pl core -Ptest -Dtest=JRubyClassLoaderTest testruns them.