Skip to content

File handle in SpringBootJoranConfigurator should be closed - #51398

Open
dlwldn30 wants to merge 1 commit into
spring-projects:4.0.xfrom
dlwldn30:close-aot-file-content-stream
Open

File handle in SpringBootJoranConfigurator should be closed#51398
dlwldn30 wants to merge 1 commit into
spring-projects:4.0.xfrom
dlwldn30:close-aot-file-content-stream

Conversation

@dlwldn30

@dlwldn30 dlwldn30 commented Aug 21, 2026

Copy link
Copy Markdown

Sorry for the unrequested rebase on #51385 — you had said you had the branch
locally and I should have left it alone.

Re-submitted from a user-account fork, so "Allow edits from maintainers" applies
here and the tweaks you had locally should push cleanly this time. The change
itself is identical, but the commit is the 4.0.x rebase (915e4775) rather
than the main one you have locally (16f5fffd), since you had retargeted the
base.

SpringBootJoranConfigurator.RequireNewOrMatchingContentFileHandler compares the
resource it is about to write against what is already on disk:

byte[] existingContent = content.getInputStream().readAllBytes();

InputStream.readAllBytes() does not close the stream, and the stream is never
assigned to anything, so nothing can close it afterwards. During AOT processing
the handler is a FileSystemGeneratedFiles.FileSystemFileHandler whose content
supplier returns a FileSystemResource, so this is a real file handle. It is
reached whenever more than one application context contributes the same
resource. FileSystemGeneratedFiles already uses try-with-resources on the
other side of the same interface.

The fix reads the existing content inside a try-with-resources block, three
lines. The test supplies its own GeneratedFiles and a FileHandler whose
content records when its stream is closed, then drives the AOT contribution
through applyTo.

Verified on 4.0.x: aotContributionClosesExistingFileContent fails without the
production change and passes with it, :core:spring-boot:test 3767 tests with
0 failures and 14 skipped, and checkFormatMain, checkFormatTest,
checkstyleMain and checkstyleTest pass.

Contributed on behalf of Goatshave.

RequireNewOrMatchingContentFileHandler reads the already generated file
through content.getInputStream().readAllBytes(). InputStream.readAllBytes
does not close the stream, and the stream is never assigned, so it cannot
be closed at all.

During AOT processing the content is a FileSystemResource, so each
comparison leaks a file handle. FileSystemGeneratedFiles already uses
try-with-resources when it consumes an InputStreamSource.

Read the existing content inside a try-with-resources block.

See spring-projectsgh-51385

Signed-off-by: dlwldn30 <dlwldn30@naver.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 21, 2026
@dlwldn30

Copy link
Copy Markdown
Author

@snicoll both are re-submitted from my user account now — #51398 (this one, 4.0.x) and #51399 — and "Allow edits from maintainers" is in effect on both, so the tweaks you had locally should push cleanly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants