On Wed, 18 Jun 2025 16:27:03 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:
>> 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 It also throws an exception this way: jshell> new ImageIcon((URL) null, ""); | Exception java.lang.NullPointerException: Cannot invoke "java.net.URL.toString()" because "url" is null | at SunToolkit.getImageFromHash (SunToolkit.java:699) | at SunToolkit.getImage (SunToolkit.java:735) | at ImageIcon.<init> (ImageIcon.java:215) | at (#4:1) Thus, `ImageIcon(URL)` constructors have to be updated… under a new issue, maybe? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/25767#discussion_r2155174950