On Fri, 6 Jun 2025 03:29:47 GMT, Prasanta Sadhukhan <psadhuk...@openjdk.org> wrote:
> ImageIcon.getNextID uses `mediaTrackerID ` which do not detect overflow. > > Theoretically there is a possibility that there can be overflow in the long > time run or for large number of created "imageIcon" > > Made sure there is no overflow and treat that loadImage as ABORTED > > No regression testcase as it addresses theoretical possibility.. > > 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. If mediaTrackerId overflows then id will increment backwards without any fix like -2147483648, -2147483647, -2147483646, -2147483645, -2147483644 etc so it will take another Integer.MAX_VALUE+1 images to gain positive numbers..Not sure having overflown negative ids for all these images will cause any issues or not? ------------- PR Comment: https://git.openjdk.org/jdk/pull/25666#issuecomment-2963063787