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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user