Skip to content

File handle in SpringBootJoranConfigurator should be closed - #51398

Merged
snicoll merged 2 commits into
spring-projects:4.0.xfrom
dlwldn30:close-aot-file-content-stream
Aug 24, 2026
Merged

snicoll merged 2 commits into
spring-projects:4.0.xfrom
dlwldn30:close-aot-file-content-stream

Conversation

@dlwldn30

@dlwldn30 dlwldn30 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. label Aug 21, 2026
@dlwldn30

Copy link
Copy Markdown
Contributor 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.

dlwldn30 and others added 2 commits August 24, 2026 08:05
RequireNewOrMatchingContentFileHandler reads the already generated file
through content.getInputStream().readAllBytes(). That method 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-51398

Signed-off-by: dlwldn30 <dlwldn30@naver.com>
@snicoll snicoll self-assigned this Aug 24, 2026
@snicoll snicoll added type: bug A general bug and removed status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. labels Aug 24, 2026
@snicoll
snicoll force-pushed the close-aot-file-content-stream branch from 915e477 to 5402f5b Compare August 24, 2026 06:06
@snicoll snicoll added this to the 4.0.9 milestone Aug 24, 2026
@snicoll
snicoll merged commit d3547de into spring-projects:4.0.x Aug 24, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants