RFR: 8159055: ImageIcon.setImage can't handle null parameter [v14]
Alexey Ivanov
aivanov at openjdk.org
Tue Jul 8 12:58:45 UTC 2025
On Tue, 8 Jul 2025 06:22:28 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:
>
> constructor test removal
Marked as reviewed by aivanov (Reviewer).
test/jdk/javax/swing/ImageIcon/ImageIconNullImageTest.java line 34:
> 32: import javax.swing.ImageIcon;
> 33:
> 34: public class ImageIconNullImageTest {
I guess we're going to update the test later with follow-up fixes…
However, I suggest dropping `ImageIcon-` from the test class name — the test is in `ImageIcon` folder, therefore it tests `ImageIcon`.
-------------
PR Review: https://git.openjdk.org/jdk/pull/25767#pullrequestreview-2997530641
PR Review Comment: https://git.openjdk.org/jdk/pull/25767#discussion_r2192450089
More information about the client-libs-dev
mailing list