I have a problem reading JPEG images in Java using Image IO in a multi-threaded environment. Problems only arise if multiple threads try to read the image.
Symptoms range from improper profile loading to an exception:
java.awt.color.CMMException: LCMS error 13: Couldn't link the profiles
No matter how I read the image, using ImageIO.read or using ImageReader .
The source data (image) is completely isolated and immutable.
This problem may be related to: https://bugs.openjdk.java.net/browse/JDK-8041429 and https://bugs.openjdk.java.net/browse/JDK-8032243
The question is, is there any other way to read JPEG files with ImageIO with multiple streams. ImageIO seems to have a problem with changing the state of the color profiles of the image together, which I do not control. Only the solution that I see completely isolates it at the JVM level, which sounds like a bad idea.
I am using Oracle JDK 8u25 . Changing the version of the JDK update does not affect the problem (and not the main version), I can not use JDK 7 without overwriting large pieces of code.
Code for reference.
ImageInputStream input = new MemoryCacheImageInputStream(inputStream); Iterator<ImageReader> readers = ImageIO.getImageReaders(input); if (!readers.hasNext()) { throw new IllegalArgumentException("No reader for: " + dataUuid.toString()); } ImageReader reader = readers.next(); try { reader.setInput(input); BufferedImage image = reader.read(0, reader.getDefaultReadParam());
source share