RFR: 8159055: ImageIcon.setImage and ImageIcon(Image) constructor can't handle null parameter [v11]

Alexey Ivanov aivanov at openjdk.org
Wed Jul 2 19:40:43 UTC 2025


On Tue, 24 Jun 2025 14:01:04 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

>> Note that this was a preview language feature until **JDK 25**.
>
> I haven't done my due diligence to verify whether this feature can be used. Even if this particular way can't be used, it's still a viable option, just move the code above into a helper method.
> 
> 
>     public ImageIcon(Image image, String description) {
>         this.image = image;
>         this.description = description;
> 
>         loadImage(image);
>     }
> 
>     public ImageIcon (Image image) {
>         this(image, getImageComment(image));
>     }
> 
>     /**
>      * {@return the {@code "comment"} property of the image
>      * if the value of the property is a sting}
>      * @param image the image to get the {@code "comment"}  property
>      */
>     private static String getImageComment(Image image) {
>         if (image == null) {
>             return null;
>         }
> 
>         Object o = image.getProperty("comment", null);
>         return (o instanceof String) ? (String) o : null;
>     }
> 
> 
> This should be done separately from this changeset, I think, to have shorter, more specific changes.

> Note that this was a preview language feature until **JDK 25**.

Huh… We're developing JDK 26 now, so the **Flexible Constructor Bodies** [[JEP 513](https://openjdk.org/jeps/513)] feature can safely be used.

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

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


More information about the client-libs-dev mailing list