Skip to content

Commit

Permalink
Better exception dispatch when arguments out of bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-allan committed Oct 1, 2024
1 parent cb1ca8c commit e9313f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 10 additions & 5 deletions src/main/java/com/glencoesoftware/omero/zarr/ZarrPixelBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -481,10 +481,15 @@ public PixelData getTile(
// of channels can be unpredictable.
tileCache.synchronous().invalidateAll();
}
CompletableFuture<Map<List<Integer>, byte[]>> future =
tileCache.getAll(keys);
Map<List<Integer>, byte[]> values = future.join();
return toPixelData(values.get(key));
try {
return toPixelData(tileCache.getAll(keys).join().get(key));
} catch (CompletionException e) {
if (e.getCause() instanceof IllegalArgumentException) {
// Request arguments out of bounds
throw (IllegalArgumentException) e.getCause();
}
throw e;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletionException;
import java.util.stream.IntStream;

import org.junit.Assert;
Expand Down Expand Up @@ -502,7 +503,7 @@ public void testGetTileLargerThanImage()
}
}

@Test
@Test(expected = IllegalArgumentException.class)
public void testTileIntegerOverflow()
throws IOException, InvalidRangeException {
int sizeT = 1;
Expand Down Expand Up @@ -534,9 +535,8 @@ public void testTileIntegerOverflow()
}
}

@Test(expected = DimensionsOutOfBoundsException.class)
public void testTileExceedsMinMax()
throws IOException, InvalidRangeException {
@Test(expected = IllegalArgumentException.class)
public void testTileExceedsMinMax() throws IOException {
int sizeT = 1;
int sizeC = 3;
int sizeZ = 1;
Expand Down

0 comments on commit e9313f5

Please sign in to comment.