RFR: 8055461: getNextID in ImageIcon class can lead to overflow
Jeremy Wood
duke at openjdk.org
Mon Jun 9 06:12:04 UTC 2025
On Mon, 9 Jun 2025 02:14:09 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:
>> src/java.desktop/share/classes/javax/swing/ImageIcon.java line 305:
>>
>>> 303: return;
>>> 304: }
>>> 305: mTracker.addImage(image, id);
>>
>> Hmm. Is there any acceptable logging we could use here?
>>
>> (I'm just thinking: from the perspective of a developer trying to debug a customer complaint, this would be a lot easier to identify in System.err mentioned it...? Otherwise I'd start by trying to look for potential memory leaks or other red herrings.)
>
> I dont think there is any logging for this nor do we want to log...In all probability, the image will consume the heap memory so practically OOM will be raised by the time this overflow happens but it can happen if maybe all 1x1 images are used and subsequent needed memory reserved for Java process
OK. I don't feel like I really understand this fix (or the need for it), but I also am not too worried about it.
FWIW I was able to trigger this condition in an app that ran for about 30 minutes. (Maybe if I turned up the thread priority it could be faster?) I'm not going to keep exploring this, though, unless a pointed question comes up.
import javax.swing.*;
import java.awt.*;
public class ImageIconTest {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame f = new JFrame();
ImageIcon icon = new ImageIcon();
Image image = Toolkit.getDefaultToolkit().createImage("onepixel.gif");
icon.setImage(image);
JLabel label = new JLabel(icon);
f.getContentPane().add(label);
f.pack();
f.setVisible(true);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
icon.setImage(image);
}
}
});
t.start();
}
});
}
}
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25666#discussion_r2135090608
More information about the client-libs-dev
mailing list