From 7c386292bc8b3dfa532bd779d703ee27a5ecf827 Mon Sep 17 00:00:00 2001 From: Norman Rzepka Date: Thu, 30 Apr 2026 10:41:37 +0200 Subject: [PATCH] fixes #72 --- .../zarr/zarrjava/store/BufferedZipStore.java | 4 ++-- .../zarrjava/store/BufferedZipStoreTest.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/zarr/zarrjava/store/BufferedZipStore.java b/src/main/java/dev/zarr/zarrjava/store/BufferedZipStore.java index ab1afc8c..411bfa2d 100644 --- a/src/main/java/dev/zarr/zarrjava/store/BufferedZipStore.java +++ b/src/main/java/dev/zarr/zarrjava/store/BufferedZipStore.java @@ -80,7 +80,7 @@ public BufferedZipStore(@Nonnull StoreHandle underlyingStore) { } public BufferedZipStore(@Nonnull Path underlyingStore, String archiveComment) { - this(new FilesystemStore(underlyingStore.getParent()).resolve(underlyingStore.getFileName().toString()), archiveComment); + this(new FilesystemStore(underlyingStore.toAbsolutePath().getParent()).resolve(underlyingStore.getFileName().toString()), archiveComment); } public BufferedZipStore(@Nonnull Path underlyingStore) { @@ -108,7 +108,7 @@ public BufferedZipStore(@Nonnull StoreHandle underlyingStore, boolean flushOnWri } public BufferedZipStore(@Nonnull Path underlyingStore, String archiveComment, boolean flushOnWrite) { - this(new FilesystemStore(underlyingStore.getParent()).resolve(underlyingStore.getFileName().toString()), archiveComment, flushOnWrite); + this(new FilesystemStore(underlyingStore.toAbsolutePath().getParent()).resolve(underlyingStore.getFileName().toString()), archiveComment, flushOnWrite); } public BufferedZipStore(@Nonnull Path underlyingStore, boolean flushOnWrite) { diff --git a/src/test/java/dev/zarr/zarrjava/store/BufferedZipStoreTest.java b/src/test/java/dev/zarr/zarrjava/store/BufferedZipStoreTest.java index 742a18da..88ab1d65 100644 --- a/src/test/java/dev/zarr/zarrjava/store/BufferedZipStoreTest.java +++ b/src/test/java/dev/zarr/zarrjava/store/BufferedZipStoreTest.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.zip.ZipEntry; @@ -174,6 +175,21 @@ public void testZipStoreV2(boolean flushOnWrite) throws ZarrException, IOExcepti } + @Test + public void testBufferedZipStoreWithRelativePath() throws ZarrException, IOException { + // Path.of("filename.zip") has no parent component — getParent() returns null, + // which previously caused a NullPointerException in FilesystemStore.resolveKeys(). + Path relPath = Paths.get("testRelativePath.zip"); + Path absPath = relPath.toAbsolutePath(); + try { + BufferedZipStore store = new BufferedZipStore(relPath); + writeTestGroupV3(store.resolve(), true); + store.flush(); + } finally { + Files.deleteIfExists(absPath); + } + } + @Override Store writableStore() { Path path = TESTOUTPUT.resolve("writableStore.ZIP");