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));