Skip to content

Commit

Permalink
Fix NullPointerException triggered by calling imgLabeling.getType().c…
Browse files Browse the repository at this point in the history
…lear()

The bug was discovered by compiling and testing Labkit against
imglib2-7.1. Trying to use the brush in Labkit would trigger this
NullPointerException.
  • Loading branch information
maarzt authored and tpietzsch committed Sep 2, 2024
1 parent 5b508b6 commit 4cf94b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/net/imglib2/roi/labeling/ImgLabeling.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public LabelingType< T > firstElement()
@Override
public LabelingType< T > getType()
{
return new LabelingType<>( null, mapping, generation );
return new LabelingType<>( indexAccessible.getType(), mapping, generation );
}

@Override
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/net/imglib2/roi/labeling/ImgLabelingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
package net.imglib2.roi.labeling;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
Expand Down Expand Up @@ -174,4 +175,14 @@ public void testHashCodeAndEquals()
assertTrue( pixel.equals( expected ) );
assertEquals( expected.hashCode(), pixel.hashCode() );
}

@Test
public void testGetType()
{
ImgLabeling< String, IntType > imgLabeling = new ImgLabeling<>( ArrayImgs.ints( 10, 10 ) );
LabelingType< String > type = imgLabeling.getType().createVariable();
type.clear();
type.add( "A" );
assertEquals( Collections.singleton( "A" ), type );
}
}

0 comments on commit 4cf94b5

Please sign in to comment.