1

I am currently trying to merge a seperate project into ours, that uses deeplearning4j-core as a dependency. deeplearning4j-core uses com.twelvemonkeys.imageio internally, which registers plugins into ImageIO.read(). However, that seems to break all ImageIO.read calls we currently have in production, with the following error message:

javax.imageio.IIOException: No SOF segment in stream
    at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader.getSOF(Unknown Source) ~[imageio-jpeg-3.1.1.jar:3.1.1]
    at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader.read(Unknown Source) ~[imageio-jpeg-3.1.1.jar:3.1.1]
    at com.github.jaiimageio.impl.plugins.tiff.TIFFJPEGDecompressor.decodeRaw(TIFFJPEGDecompressor.java:226) ~[jai-imageio-core-1.4.0.jar:1.4.0]
    at com.github.jaiimageio.plugins.tiff.TIFFDecompressor.decode(TIFFDecompressor.java:2583) ~[jai-imageio-core-1.4.0.jar:1.4.0]
    at com.github.jaiimageio.impl.plugins.tiff.TIFFImageReader.decodeTile(TIFFImageReader.java:1144) ~[jai-imageio-core-1.4.0.jar:1.4.0]
    at com.github.jaiimageio.impl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1414) ~[jai-imageio-core-1.4.0.jar:1.4.0]
    at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1468) ~[na:na]
    at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1315) ~[na:na]
  [production code]

We are reading in TIFF files that had no issue being recognized before. Now they cannot be read at all and throw the exception listed above 90% of the time the software is started. 10% of the time, it works without a hitch until the JVM suspends. This makes me think it's a loading order issue, but I am too inexperienced to work it out.

I know the underlying issue is probably greater, but getting it up and running right now has a high priority first and foremost.

We are using gradle.

Joe
  • 216
  • 4
  • 18
  • Looks like this is issue with target library, because missing dependencies leads to "Class Not Found Exception" errors. Also I found, that it can mean that incorrect file was provided: https://github.com/haraldk/TwelveMonkeys/issues/278 – Manushin Igor Mar 05 '20 at 13:11
  • 1
    Yes, I found the same. What I am saying is though, our ImageIO.read calls were working well enough before we added the dependency to deep learning, but after adding that one all our ImageIO.calls broke because the reading calls now get delegated to TwelveMonkeys inside of ImageIO, which is causing the exception – Joe Mar 05 '20 at 13:33
  • 1
    Can you exclude the twelvemonkeys depedency without breaking anything else? If you already have something registered to read the TIFFs then it may not be an issue. – heisbrandon Mar 09 '20 at 17:40
  • @Joe: Author of the TwelveMonkeys library here. I see that you are using a combination of (a forked) JAI TIFF reader plugin and our JPEG plugin [as in the issue mentioned above](https://github.com/haraldk/TwelveMonkeys/issues/278#issuecomment-272281609) that doesn't work well. It will probably work better if you choose our TIFF plugin as well (either by removing/excluding the dependency, or specifying the order so our plugin is chosen before the JAI version) , or as you suggest, remove/exclude the dependencies on TwelveMonkeys. – Harald K Mar 10 '20 at 08:34
  • 1
    Your comment definitely helped, as it pointed me in the right direction. Thanks to [this question](https://stackoverflow.com/questions/38190507/how-to-exclude-specific-tiff-reader-from-imageio) I figured out that I can reorder / remove plugin dependencies after the JVM booted. I ended up writing a configuration class that simply removes the TIFF plugin from JAI and sun, and now TIFF files work flawlessly again. It's a very brittle solution for sure, but it helped get everything running again. Keeping this question up for other solving approaches. – Joe Mar 11 '20 at 12:47

0 Answers0