Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NullPointerException triggered by calling imgLabeling.getType() #73

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );
}
}
Loading