Null pointer exception using @Parameter Dataset (solved)

Edit: I figured out the issue if anyone ever runs into this same problem. You have to set the Dataset Parameter to not persist, otherwise it tries to load the Dataset from the last time the application was run (which is no longer the same object instance, even if it is the same image). Ex:

@Parameter(label = "Image 1: ", persist = false)
private Dataset dataset1;

This fixed the issue completely.


Hi all,

My plugin is suddenly (and inexplicably) getting a null pointer exception on startup when using the @Parameter Dataset to load an image:

java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.NullPointerException
	at net.imagej.legacy.LegacyService.runLegacyCompatibleCommand(LegacyService.java:307)
	at net.imagej.legacy.DefaultLegacyHooks.interceptRunPlugIn(DefaultLegacyHooks.java:166)
	at ij.IJ.runPlugIn(IJ.java)
	at ij.Executer.runCommand(Executer.java:150)
	at ij.Executer.run(Executer.java:68)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.util.concurrent.ExecutionException: java.lang.NullPointerException
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at net.imagej.legacy.LegacyService.runLegacyCompatibleCommand(LegacyService.java:303)
	... 5 more
Caused by: java.lang.NullPointerException
	at io.scif.services.DefaultInitializeService.initializeReader(DefaultInitializeService.java:87)
	at io.scif.img.ImgOpener.createReader(ImgOpener.java:483)
	at io.scif.img.ImgOpener.openImgs(ImgOpener.java:242)
	at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:152)
	at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:133)
	at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:138)
	at io.scif.convert.FileToDatasetConverter.convert(FileToDatasetConverter.java:66)
	at org.scijava.convert.AbstractConvertService.convert(AbstractConvertService.java:125)
	at org.scijava.convert.AbstractDelegateConverter.convert(AbstractDelegateConverter.java:53)
	at org.scijava.convert.AbstractConvertService.convert(AbstractConvertService.java:125)
	at org.scijava.module.DefaultModuleService.load(DefaultModuleService.java:316)
	at org.scijava.module.DefaultModuleService.loadInput(DefaultModuleService.java:544)
	at org.scijava.module.DefaultModuleService.lambda$loadInputs$1(DefaultModuleService.java:346)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1080)
	at org.scijava.module.DefaultModuleService.loadInputs(DefaultModuleService.java:346)
	at org.scijava.module.process.LoadInputsPreprocessor.process(LoadInputsPreprocessor.java:58)
	at org.scijava.module.ModuleRunner.preProcess(ModuleRunner.java:102)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:154)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:124)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:63)
	at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:225)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

I have multiple images open when I run the plugin, enough for each Dataset parameter, and have updated ImageJ/FIJI. Here’s the code for all my parameters (I’ve commented out the run() method, so I know it’s somewhere in here):

@Plugin(type = Command.class, menuPath = "Analyze>Colocalization>Colocalization by Correlation")
public class Colocalization_by_Cross_Correlation implements Command{
    
    @Parameter
    private LogService logService;

    @Parameter(label = "Image 1: ")
    private Dataset dataset1;

    @Parameter(label = "Image 2: ")
    private Dataset dataset2;

    @Parameter(label = "No mask (not recommended)?", description = "When checked, performs Costes randomization over the entire image")
    private boolean maskAbsent;

    @Parameter(label = "Mask: ", required = false)
    private Dataset maskDataset;

    @Parameter(label = "PSF xy(pixel units): ", min = "1")
    private long PSFxy;

    @Parameter(label = "PSF z(pixel units), enter 1 for 2D image:", min = "1")
    private long PSFz;

    @Parameter(label = "Cycle count: ", min = "1")
    private long cycles;

    @Parameter(label = "Show intermediate images? ", description = "Shows ")
    private boolean intermediates;

I’ve tried removing “required=false” on the maskDataset, but this didn’t fix the issue. I know that I could change this to use Files instead of Datasets, then open the images in the plugin, I’d just prefer to have the plugin work on already open images for simplicity. Any help would be really appreciated.

2 Likes