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

ExE Boss duke at openjdk.org
Thu Jul 3 08:41:41 UTC 2025


On Wed, 2 Jul 2025 19:38:11 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

>> 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.

Yes, but it complicates backports.

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

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


More information about the client-libs-dev mailing list