diff --git a/src/main/java/org/scijava/io/handle/DataHandleService.java b/src/main/java/org/scijava/io/handle/DataHandleService.java index f2a24ba6d..8bc55a2b6 100644 --- a/src/main/java/org/scijava/io/handle/DataHandleService.java +++ b/src/main/java/org/scijava/io/handle/DataHandleService.java @@ -33,7 +33,6 @@ package org.scijava.io.handle; import java.io.IOException; -import java.util.Objects; import org.scijava.io.IOService; import org.scijava.io.location.Location; @@ -72,12 +71,13 @@ default Class getType() { * * @param location the location to test * @return The result of {@link DataHandle#exists()} on a newly created handle - * on this location - * @throws IOException + * on this location. Also returns {@code false} if the handle can not + * be created. + * @throws IOException if the creation of the handle fails exceptionally */ default boolean exists(final Location location) throws IOException { try (DataHandle handle = create(location)) { - return handle.exists(); + return handle == null ? false : handle.exists(); } } @@ -86,18 +86,22 @@ default boolean exists(final Location location) throws IOException { * reading. * * @param handle the handle to wrap + * @return The handle wrapped in a read-only buffer, or {@code null} if the + * input handle is {@code null} * @see ReadBufferDataHandle#ReadBufferDataHandle(DataHandle) */ default DataHandle readBuffer(final DataHandle handle) { - Objects.nonNull(handle); - return new ReadBufferDataHandle(handle); + return handle == null ? null : new ReadBufferDataHandle(handle); } /** * Creates a {@link DataHandle} on the provided {@link Location} wrapped in a * read-only buffer for accelerated reading. * - * @param location the handle to wrap + * @param location the Location to create a buffered handle on. + * @return A {@link DataHandle} on the provided location wrapped in a + * read-only buffer, or {@code null} if no handle could be created for + * the location. * @see ReadBufferDataHandle#ReadBufferDataHandle(DataHandle) */ default DataHandle readBuffer(final Location location) { @@ -110,10 +114,11 @@ default DataHandle readBuffer(final Location location) { * accelerated writing. * * @param handle the handle to wrap + * @return the handle wrapped in a write-only buffer or {@code null} if the + * provided handle is {@code null} * @see WriteBufferDataHandle#WriteBufferDataHandle(DataHandle) */ default DataHandle writeBuffer(final DataHandle handle) { - Objects.nonNull(handle); - return new WriteBufferDataHandle(handle); + return handle == null ? null : new WriteBufferDataHandle(handle); } }