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(
	at net.imagej.legacy.DefaultLegacyHooks.interceptRunPlugIn(
	at ij.IJ.runPlugIn(
	at ij.Executer.runCommand(
Caused by: java.util.concurrent.ExecutionException: java.lang.NullPointerException
	at java.util.concurrent.FutureTask.get(
	at net.imagej.legacy.LegacyService.runLegacyCompatibleCommand(
	... 5 more
Caused by: java.lang.NullPointerException
	at io.scif.img.ImgOpener.createReader(
	at io.scif.img.ImgOpener.openImgs(
	at io.scif.convert.FileToDatasetConverter.convert(
	at org.scijava.convert.AbstractConvertService.convert(
	at org.scijava.convert.AbstractDelegateConverter.convert(
	at org.scijava.convert.AbstractConvertService.convert(
	at org.scijava.module.DefaultModuleService.load(
	at org.scijava.module.DefaultModuleService.loadInput(
	at org.scijava.module.DefaultModuleService.lambda$loadInputs$1(
	at java.util.ArrayList.forEach(
	at java.util.Collections$UnmodifiableCollection.forEach(
	at org.scijava.module.DefaultModuleService.loadInputs(
	at org.scijava.module.process.LoadInputsPreprocessor.process(
	at org.scijava.module.ModuleRunner.preProcess(
	at org.scijava.thread.DefaultThreadService.lambda$wrap$2(
	at java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.util.concurrent.ThreadPoolExecutor$

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{
    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.