Fix NPE in TemporaryBuffer when writing to closed buffer#6
Merged
Conversation
When a TemporaryBuffer exceeds its in-core limit, switchToOverflow() sets blocks=null. If close() is then called, overflow is also set to null. Any subsequent write attempt caused a NullPointerException when accessing blocks.size(). This occurs during error cleanup in HTTP transport when BasePackConnection.close() tries to write an end marker via PacketLineOut.end() after the buffer has already been closed. Add defensive checks in write() methods to throw IOException instead of NPE when the buffer is closed. This allows the original transport error to propagate correctly.
greg-at-moderne
approved these changes
Dec 3, 2025
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.
Problem
Large repository operations that exceed the buffer's in-core limit can trigger a
NullPointerExceptioninTemporaryBuffer.write():This happens when:
switchToOverflow()setsblocks = nullclose()is called, settingoverflow = nullpckOut.end()which tries to write to the closed bufferblocks.size()The NPE masks the original transport error because it's thrown during cleanup.
Solution
Add defensive checks in
write()methods to throwIOExceptioninstead of NPE when the buffer is in a closed state (bothblocksandoverfloware null).Why this works
The key insight is in
BasePackConnection.close():close()completes → original error propagatesThis allows the actual transport failure to be reported instead of the cryptic NPE.