On Wed, 23 Jul 2025 08:43:33 GMT, Prasanta Sadhukhan <psadhuk...@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:
> 
>   Remove unneeded vars

test/jdk/javax/swing/ImageIcon/ImageIconTest.java line 54:

> 52: 
> 53:         for (ArgType a : ArgType.values()) {
> 54:             for (final boolean invalid : new boolean[]{false, true}) {

This "invalid==false" means use null and "invalid=true" means use non-null but 
invalid image data 
seems odd.

Can we rename invalid to "invalidImageData" ? Or may be better an other enum ?

test/jdk/javax/swing/ImageIcon/ImageIconTest.java line 103:

> 101:                         passed = true;
> 102:                     }
> 103:                 } catch (Exception ex) {

What's this block for ? What other kind of exception besides NPE can we get ?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25767#discussion_r2229365272
PR Review Comment: https://git.openjdk.org/jdk/pull/25767#discussion_r2229365160

Reply via email to