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

Alexey Ivanov aivanov at openjdk.org
Mon Jun 16 15:29:30 UTC 2025


On Mon, 16 Jun 2025 15:21:27 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

>> src/java.desktop/share/classes/javax/swing/ImageIcon.java line 380:
>> 
>>> 378:         if (image == null) {
>>> 379:             return;
>>> 380:         }
>> 
>> Should `setImage` clear / update the description automatically?
>> 
>> It's up for discussion… What do you think?
>
> Update the description from where? Its not overridden method..

Set it to `null` if the image is `null` or load it from the `"comment"` property as the constructor does.

However, it's safer to leave it untouched. After all, constructors are used to initialise the fields of the object so it makes sense to try to set a description whereas changing the icon doesn't necessarily mean the description needs to change; if it does, call `setDescription` explicitly.

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

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


More information about the client-libs-dev mailing list