BF Plugins: NPE when using Virtual Stack
Issue was reported on forum thread https://forum.image.sc/t/ome-tiff-issue-with-virtual-stack-java-nio-channels-closedchannelexception/66802
java.lang.NullPointerException
at loci.formats.in.MinimalTiffReader.initFile(MinimalTiffReader.java:459)
at loci.formats.FormatReader.setId(FormatReader.java:1443)
at loci.formats.in.OMETiffReader.initializeReader(OMETiffReader.java:1476)
at loci.formats.in.OMETiffReader.openBytes(OMETiffReader.java:368)
at loci.formats.ChannelFiller.openBytes(ChannelFiller.java:167)
at loci.formats.ChannelSeparator.openBytes(ChannelSeparator.java:229)
at loci.formats.ChannelSeparator.openBytes(ChannelSeparator.java:161)
at loci.formats.ReaderWrapper.openBytes(ReaderWrapper.java:334)
at loci.formats.DimensionSwapper.openBytes(DimensionSwapper.java:233)
at loci.formats.ReaderWrapper.openBytes(ReaderWrapper.java:334)
at loci.formats.ReaderWrapper.openBytes(ReaderWrapper.java:334)
at loci.plugins.util.ImageProcessorReader.openProcessors(ImageProcessorReader.java:186)
at loci.plugins.util.ImageProcessorReader.openProcessors(ImageProcessorReader.java:83)
at loci.plugins.util.ImageProcessorSource.getObject(ImageProcessorSource.java:72)
at loci.formats.cache.Cache.recache(Cache.java:204)
at loci.formats.cache.Cache.recache(Cache.java:224)
at loci.formats.cache.Cache.setCurrentPos(Cache.java:175)
at loci.plugins.util.BFVirtualStack.getProcessor(BFVirtualStack.java:176)
at ij.ImagePlus.setSlice(ImagePlus.java:1961)
at ij.gui.StackWindow.setPosition(StackWindow.java:312)
at ij.ImagePlus.setPosition(ImagePlus.java:1844)
at ij.ImagePlus.setPositionWithoutUpdate(ImagePlus.java:1858)
at loci.plugins.in.Colorizer$1.show(Colorizer.java:186)
The same exception was reproduced using BF 6.9.1 when switching quickly between planes with virtual stack. From debugging this appears to happen sue to a race condition as the following steps occur when switching between planes:
- BFVirtualStack call getSize which in turn calls setSeries on the reader
- setSeries on OMETiffReader calls close on underlying readers and tiffparsers
- initFile on MinimalTiffReader is called for the new plane
- initFile sets up a TiffParser
- the close function completes and sets TiffParser to null
- initFile tries to use the new TiffParser but finds it has been closed and the NPE is thrown
The first call from BFVirtualStack to setSeries every time getSize is called seems unnecessary and can likely be removed. However further testing would be needed to ensure this doesn't cause any unforeseen regressions.
This issue has been mentioned on Image.sc Forum. There might be relevant details there:
https://forum.image.sc/t/ome-tiff-issue-with-virtual-stack-java-nio-channels-closedchannelexception/66802/2