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

Alexey Ivanov aivanov at openjdk.org
Tue Jul 29 13:04:10 UTC 2025


On Tue, 29 Jul 2025 12:44:24 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..
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Rectify @throws clause, update test to delete file

`ImageIcon` changes look good to me.

I admit I can't understand what the test is doing, and I don't have to time to study the test thoroughly.

However, I'm still for documenting null and invalid parameters under a separate bug id; under this bug id modify `Image.setImage` to accept `null` as it's reported in the bug ([JDK-8159055](https://bugs.openjdk.org/browse/JDK-8159055)) and as it was done in this PR initially.

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

Marked as reviewed by aivanov (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/25767#pullrequestreview-3067442617


More information about the client-libs-dev mailing list