Skip to content

Commit b658367

Browse files
gselzerctrueden
authored andcommitted
Ensure empty label sets don't throw exceptions
1 parent 693788a commit b658367

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/main/java/net/imglib2/labeling/DefaultLabelingIOService.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ private <S, T, I extends IntegerType<I>> ImgLabeling<T, I> buildImgLabelingAndIm
140140
}
141141

142142
private <T, S> void createLabelsets(LabelingMapping<T> labelingMapping, LabelingData<T, S> labelingData) {
143-
if (labelingMapping.getLabels().stream().findFirst().get() instanceof Integer) {
143+
Optional<T> optional = labelingMapping.getLabels().stream().findFirst();
144+
if (optional.isPresent() && optional.get() instanceof Integer) {
144145
Map<String, Set<Integer>> labels = new HashMap<>();
145146
for (int i = 0; i < labelingMapping.numSets(); i++) {
146147
labels.put(Integer.toString(i), (Set<Integer>) labelingMapping.labelsAtIndex(i));

0 commit comments

Comments
 (0)