Synchronize usages of ImageIO.read(...)

ImageIO.read(...) is not really thread-safe, as calling it on several threads at the same time can cause NullPointerExceptions and ConcurrentModificationExceptions, as reported in https://bugs.openjdk.java.net/browse/JDK-8058973 and https://bugs.openjdk.java.net/browse/JDK-6986863.

This commit changes all usages of this method to synchronize on ImageIO.class, so the method is never run asynchronously.
This commit is contained in:
Lotto
2018-03-07 20:06:16 +01:00
parent 12329828ea
commit 054dd4852d
29 changed files with 203 additions and 61 deletions

View File

@@ -95,8 +95,10 @@ public class ItemClient
}
InputStream in = response.body().byteStream();
BufferedImage imageIcon = ImageIO.read(in);
return imageIcon;
synchronized (ImageIO.class)
{
return ImageIO.read(in);
}
}
}