Skip to content

Prevent File Channel Null Pointer Exceptions when writing large data sets#190

Merged
nicost merged 3 commits into
micro-manager:mainfrom
nicost:big
Jun 17, 2026
Merged

Prevent File Channel Null Pointer Exceptions when writing large data sets#190
nicost merged 3 commits into
micro-manager:mainfrom
nicost:big

Conversation

@nicost

@nicost nicost commented Jun 17, 2026

Copy link
Copy Markdown
Member

Instead of throwing an NPE when a File Channel is not open, re-open, write and close it again.

nicost added 2 commits June 17, 2026 15:11
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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in overwritePixels(...) that reopens the file, overwrites pixels in place, and closes immediately.
  • Bump Java artifact version from 2.19.2 to 2.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.

Comment thread java/src/main/java/org/micromanager/ndtiffstorage/NDTiffWriter.java
…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.
@nicost nicost merged commit b2b8383 into micro-manager:main Jun 17, 2026
6 checks passed
@nicost nicost deleted the big branch June 17, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants