Prevent File Channel Null Pointer Exceptions when writing large data sets#190
Merged
Conversation
This NPE is unavoidable when writing large data sets. Instead of letting it happen, re-open the file channel and write the desired data and close it again to avoid leaving files open.
There was a problem hiding this comment.
Pull request overview
Prevents NullPointerException during in-place pixel overwrites when a rotated/finished NDTiffWriter no longer has an active FileChannel_, by reopening the underlying TIFF file for the overwrite operation.
Changes:
- Add a null-
fileChannel_fallback inoverwritePixels(...)that reopens the file, overwrites pixels in place, and closes immediately. - Bump Java artifact version from
2.19.2to2.19.3.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
java/src/main/java/org/micromanager/ndtiffstorage/NDTiffWriter.java |
Reopen-and-write path for overwriting pixels when the writer has been finished/rotated. |
java/pom.xml |
Patch version bump for the release containing the fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…fer) now runs whether or not ch.write throws, so a write/IO failure can't leak a large direct buffer. (Recycle runs before raf.close(), both in finally — order is fine since recycling just returns the buffer to the pool.) 2. Partial-write loop — while (byteBuffer.hasRemaining()) pos += ch.write(byteBuffer, pos). Positional writes can be short, so it loops until the buffer is fully written, advancing the file position by the bytes actually written each iteration. The relative position of the buffer auto-advances (positional write consumes from position()), and pos tracks the file offset independently — correct.
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.
Instead of throwing an NPE when a File Channel is not open, re-open, write and close it again.