RFR: 8159055: ImageIcon setImage and constructor can't handle null parameter [v5]

Alexey Ivanov aivanov at openjdk.org
Wed Jun 18 16:29:32 UTC 2025


On Wed, 18 Jun 2025 03:41:32 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

>> Note that "ImageIcon(URL location)" will throw npe as well, do we want to ignore it or specify NPE? That is actually interesting question since initially some of methods throw NPE and another ignore the image.
>
> ImageIcon(URL) will call ImageIcon(URL, String) where already image null check was there so I guess it will not throw NPE before fix too..

Indeed, it throws `NullPointerException`:


jshell> import javax.swing.ImageIcon;

jshell> import java.net.URL;

jshell> new ImageIcon((URL) null);
|  Exception java.lang.NullPointerException: Cannot invoke "java.net.URL.toExternalForm()" because "location" is null
|        at ImageIcon.<init> (ImageIcon.java:234)
|        at (#3:1)


https://github.com/openjdk/jdk/blob/984d7f9cdfb0d75ea906ce32df0b6c447f4d5954/src/java.desktop/share/classes/javax/swing/ImageIcon.java#L202-L204

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

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


More information about the client-libs-dev mailing list