On Wed, 11 Jun 2025 13:31:37 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:

> Won;t it better and simpler to make the id "long" which will make it use 2*64 
> images in one application?

Likely no application loads more than 2 billion images; it's even less likely 
that an application will load more than 2⁶⁴ images which is closed more than 
10¹⁹.

In fact, it seems to me that nothing will actually break when the integer 
counter in `mediaTrackerId` overflows into negative numbers and then overflows 
back to positive numbers again. This id is used to identify an image in the 
loading queue.

Because of negative id, the order of `MediaEntry` elements in the list may be 
broken.

https://github.com/openjdk/jdk/blob/c98dffa186d48c41e76fd3a60e0129a8da60310f/src/java.desktop/share/classes/java/awt/MediaTracker.java#L884-L887

It may result in malfunctioning… or not. If not, nothing bad will happen.

Having said that, I think that *no fix is necessary*. Yes, `mediaTrackerId` may 
overflow and wrap around in an application that loads billions of images, but 
is it really a problem if everything continue to work?

A problem would occur if and only if an image with id of 1, 2… still exists in 
the `MediaTracker` queue, which is ***highly* unlikely**. `ImageIcon` removes 
itself from the `MediaTracker` as soon as the image loads, successfully or not, 
which means by the time `mediaTrackerId` wraps around into positive numbers 
again, the first images are long gone from the `MediaTracker` queue.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/25666#issuecomment-2962945456

Reply via email to