Close class resource InputStream in ThrowawayClassLoader#36933
Open
junhyeong9812 wants to merge 1 commit into
Open
Close class resource InputStream in ThrowawayClassLoader#36933junhyeong9812 wants to merge 1 commit into
junhyeong9812 wants to merge 1 commit into
Conversation
ThrowawayClassLoader#loadClassFromResource opened an InputStream via getResourceAsStream(...) but never closed it. The stream leaked on both the success path (after defineClass) and the IOException path, as the surrounding try block had neither a finally nor a try-with-resources. Adopt the existing inputStream variable as a try-with-resources resource so that it is closed on every path, leaving the loading logic unchanged. Signed-off-by: junhyeong9812 <pickjog@gmail.com>
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.
Overview
ThrowawayClassLoader#loadClassFromResourceopens anInputStreamviagetResourceAsStream(...)but never closes it. The stream leaks on both thesuccess path (after
defineClass) and theIOExceptionpath, since thesurrounding
tryblock has neither afinallynor a try-with-resources.Fix
Adopt the existing
inputStreamvariable as a try-with-resources resource so itis closed on every path, leaving the loading logic unchanged:
A regression test (
ThrowawayClassLoaderTests) verifies the stream is closed byrouting a tracked
InputStreamthrough the resource fallback path.