RFR: 8159055: ImageIcon.setImage and ImageIcon(Image) constructor can't handle null parameter [v10]
Alexey Ivanov
aivanov at openjdk.org
Fri Jun 20 12:17:32 UTC 2025
On Thu, 19 Jun 2025 10:14:42 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:
>> Prasanta Sadhukhan has updated the pull request incrementally with two additional commits since the last revision:
>>
>> - Test fix
>> - javadoc wording..clear image desscription if image is null
>
> src/java.desktop/share/classes/javax/swing/ImageIcon.java line 389:
>
>> 387: this.image = image;
>> 388: if (image == null) {
>> 389: this.description = null;
>
> We must not change the description. Why do we enforce resetting the description to `null`?
>
> The app is still free to change the description to an arbitrary value using `setDescription` even if the image is `null`.
**I *strongly* disagree to changing the value of `description`** here, even though [I brought up this concern](https://github.com/openjdk/jdk/pull/25767#discussion_r2150249349).
This does not make sense. Consider the following code snippet:
ImageIcon im = new ImageIcon();
// Both image and description are null
im.setDescription("whatever");
// Now image is null, and description isn't null
im.setImage(null);
// Why does description change to null?
Both `image` and `description` are two independent fields of `ImageIcon` object, each has its own getter and setter, and each can be changed independently. We should not enforce the order of calls: if an app developer wants to set the image to `null`, temporarily or not, the value of the description has to be preserved.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25767#discussion_r2158820017
More information about the client-libs-dev
mailing list