Skip to content

Commit 02c51d1

Browse files
authored
Merge pull request #73 from zarr-developers/fix-buffered-zip-store-npe
Fixes BufferedZipStore creation
2 parents 88eb65f + 2a64217 commit 02c51d1

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/main/java/dev/zarr/zarrjava/store/BufferedZipStore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public BufferedZipStore(@Nonnull StoreHandle underlyingStore) {
8080
}
8181

8282
public BufferedZipStore(@Nonnull Path underlyingStore, String archiveComment) {
83-
this(new FilesystemStore(underlyingStore.getParent()).resolve(underlyingStore.getFileName().toString()), archiveComment);
83+
this(new FilesystemStore(underlyingStore.toAbsolutePath().getParent()).resolve(underlyingStore.getFileName().toString()), archiveComment);
8484
}
8585

8686
public BufferedZipStore(@Nonnull Path underlyingStore) {
@@ -108,7 +108,7 @@ public BufferedZipStore(@Nonnull StoreHandle underlyingStore, boolean flushOnWri
108108
}
109109

110110
public BufferedZipStore(@Nonnull Path underlyingStore, String archiveComment, boolean flushOnWrite) {
111-
this(new FilesystemStore(underlyingStore.getParent()).resolve(underlyingStore.getFileName().toString()), archiveComment, flushOnWrite);
111+
this(new FilesystemStore(underlyingStore.toAbsolutePath().getParent()).resolve(underlyingStore.getFileName().toString()), archiveComment, flushOnWrite);
112112
}
113113

114114
public BufferedZipStore(@Nonnull Path underlyingStore, boolean flushOnWrite) {

src/test/java/dev/zarr/zarrjava/store/BufferedZipStoreTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.io.IOException;
1616
import java.nio.file.Files;
1717
import java.nio.file.Path;
18+
import java.nio.file.Paths;
1819
import java.util.ArrayList;
1920
import java.util.Collections;
2021
import java.util.zip.ZipEntry;
@@ -174,6 +175,21 @@ public void testZipStoreV2(boolean flushOnWrite) throws ZarrException, IOExcepti
174175
}
175176

176177

178+
@Test
179+
public void testBufferedZipStoreWithRelativePath() throws ZarrException, IOException {
180+
// Path.of("filename.zip") has no parent component — getParent() returns null,
181+
// which previously caused a NullPointerException in FilesystemStore.resolveKeys().
182+
Path relPath = Paths.get("testRelativePath.zip");
183+
Path absPath = relPath.toAbsolutePath();
184+
try {
185+
BufferedZipStore store = new BufferedZipStore(relPath);
186+
writeTestGroupV3(store.resolve(), true);
187+
store.flush();
188+
} finally {
189+
Files.deleteIfExists(absPath);
190+
}
191+
}
192+
177193
@Override
178194
Store writableStore() {
179195
Path path = TESTOUTPUT.resolve("writableStore.ZIP");

0 commit comments

Comments
 (0)