Skip to content

Commit e537ec1

Browse files
committed
DataHandleService: improve robustness of handle access
No longer throws NullPointerException when a handle can not be created.
1 parent 3f97699 commit e537ec1

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/main/java/org/scijava/io/handle/DataHandleService.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
package org.scijava.io.handle;
3434

3535
import java.io.IOException;
36-
import java.util.Objects;
3736

3837
import org.scijava.io.IOService;
3938
import org.scijava.io.location.Location;
@@ -77,7 +76,7 @@ default Class<Location> getType() {
7776
*/
7877
default boolean exists(final Location location) throws IOException {
7978
try (DataHandle<Location> handle = create(location)) {
80-
return handle.exists();
79+
return handle == null ? false : handle.exists();
8180
}
8281
}
8382

@@ -89,8 +88,7 @@ default boolean exists(final Location location) throws IOException {
8988
* @see ReadBufferDataHandle#ReadBufferDataHandle(DataHandle)
9089
*/
9190
default DataHandle<Location> readBuffer(final DataHandle<Location> handle) {
92-
Objects.nonNull(handle);
93-
return new ReadBufferDataHandle(handle);
91+
return handle == null ? null : new ReadBufferDataHandle(handle);
9492
}
9593

9694
/**
@@ -113,7 +111,6 @@ default DataHandle<Location> readBuffer(final Location location) {
113111
* @see WriteBufferDataHandle#WriteBufferDataHandle(DataHandle)
114112
*/
115113
default DataHandle<Location> writeBuffer(final DataHandle<Location> handle) {
116-
Objects.nonNull(handle);
117-
return new WriteBufferDataHandle(handle);
114+
return handle == null ? null : new WriteBufferDataHandle(handle);
118115
}
119116
}

0 commit comments

Comments
 (0)