From b658367d7f98ad3531c00f528bffbdb4fb8135f3 Mon Sep 17 00:00:00 2001 From: Gabriel Selzer Date: Wed, 20 Apr 2022 13:14:58 -0500 Subject: [PATCH] Ensure empty label sets don't throw exceptions --- .../java/net/imglib2/labeling/DefaultLabelingIOService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/imglib2/labeling/DefaultLabelingIOService.java b/src/main/java/net/imglib2/labeling/DefaultLabelingIOService.java index 88284b8..f99b376 100644 --- a/src/main/java/net/imglib2/labeling/DefaultLabelingIOService.java +++ b/src/main/java/net/imglib2/labeling/DefaultLabelingIOService.java @@ -140,7 +140,8 @@ private > ImgLabeling buildImgLabelingAndIm } private void createLabelsets(LabelingMapping labelingMapping, LabelingData labelingData) { - if (labelingMapping.getLabels().stream().findFirst().get() instanceof Integer) { + Optional optional = labelingMapping.getLabels().stream().findFirst(); + if (optional.isPresent() && optional.get() instanceof Integer) { Map> labels = new HashMap<>(); for (int i = 0; i < labelingMapping.numSets(); i++) { labels.put(Integer.toString(i), (Set) labelingMapping.labelsAtIndex(i));