RFR: 8159055: ImageIcon.setImage can't handle null parameter

Prasanta Sadhukhan psadhukhan at openjdk.org
Thu Jun 12 06:34:09 UTC 2025


On Thu, 12 Jun 2025 03:23:30 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

> When trying to call 'icon.setImage(null);' where 'icon' is an instance of ImageIcon, a null pointer exception is thrown at runtime.
> The code tried to get the `id` for that image and instantiates `MediaTracker` to associate the null image to that `id` and checks the status of loading this null image, removes the null image from the tracker and then tries to get the image width where it throws NPE as image is null.
> 
> It's better to not go through all MediaTracker usage and bail out initially itself for null image..

I feel it's better to inform the user in the spec otherwise application may not know what will be done with NULL image

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

PR Comment: https://git.openjdk.org/jdk/pull/25767#issuecomment-2965288096


More information about the client-libs-dev mailing list