RFR: 8159055: ImageIcon.setImage and ImageIcon(Image) constructor can't handle null parameter [v10]
ExE Boss
duke at openjdk.org
Tue Jun 24 18:39:31 UTC 2025
On Fri, 20 Jun 2025 12:13:23 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:
>> 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.
Suggestion:
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25767#discussion_r2164666059
More information about the client-libs-dev
mailing list