RFR: 8055461: getNextID in ImageIcon class can lead to overflow [v2]
Phil Race
prr at openjdk.org
Fri Jun 13 21:14:39 UTC 2025
On Wed, 11 Jun 2025 15:04:21 GMT, Prasanta Sadhukhan <psadhukhan at 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..
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
>
> Reset mediaTrackerID if it overflows
Interesting that the MediaTracker is managed via an AppContext, but the id a static field.
Ah I see that there was a static field MediaTracker too, but it was deprecated in 1.8 and no longer used.
Probably being a protected field in a non-final class was the bigger issue there.
I don't see using a long as helping because aside from being able to still wrap around you
need an int to pass to MediaTracker and that isn't going to change.
New API and a ton of work would be needed to not fundamentally fix the issue.
I don't see a problem with a negative ID. MediaTracker doesn't require a positive value.
So the overflow doesn't matter.
The only issue is if one particular loadImage stalls and we cycle through and would re-use the ID.
restricting it to >=0 on its own just makes that problem more likely as you only have half the values.
I think that stalling is an unlikely problem.
But if it does happen then a new MediaTracker when we hit overflow would be a solution.
However then you need to manage a map of MediaTrackers .. it seems like a lot to do upfront.
I would just close this as will not fix.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/25666#issuecomment-2971696281
More information about the client-libs-dev
mailing list