Fix: Handle null DataBlock from NonEmptyDataBlockSupplier #183
+18
−3
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.
Fixes NullPointerException when writing blocks that are entirely filled with default values. NonEmptyDataBlockSupplier returns null for such blocks as an optimization, but the codec chain didn't handle this properly.
Changes:
DefaultDatasetAccess.writeRegionRecursive(): Add null check before encoding blocks. Return null to signal that empty blocks should not be written.
RawBlockCodecs.encode(): Add defensive null check to prevent NPE when creating LazyReadData with null dataBlock.
This allows N5Utils.saveNonEmptyBlock() to work correctly with Zarr codecs and prevents crashes when writing multi-resolution pyramids with partial blocks containing only default values.
Second commit, Fix: Skip pva.put() for null blocks in writeRegion()
Note, this is for ZarrV2 using N5ZarrWriter.
There is an extra issue reading empty blocks from a sharded ZarrV3 dataset, I am right now using
N5Utils.saveBlockinstead ofN5Utils.saveNonEmptyBlockwhen saving sharded data.Please note, this code was suggested by Claude that it would fix the issue, I have not thought it through since I am not deeply inside the N5-API. Importantly, a test that reproduces the error is available here: JaneliaSciComp/multiview-reconstruction@4789200