On Thu, 19 Jun 2025 10:06:17 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:
>> src/java.desktop/share/classes/javax/swing/ImageIcon.java line 232: >> >>> 230: Object o = image.getProperty("comment", imageObserver); >>> 231: if (o instanceof String) { >>> 232: description = (String) o; >> >> Hmm. This is wasted work if the app calls ImageIcon(Image, String) because >> that promptly over-writes whatever was obtained via this code. >> >> Also that other constructor (which github won't let me comment on) installs >> the description even if the image is null. >> That seems to be inconsistent with everything else that has a null >> description for a null image. > >> Also that other constructor (which github won't let me comment on) installs >> the description even if the image is null. > > I don't see it as a problem. > > If the app developer wants to initialise the object with `null` image and a > description, why don't we let them do it? > > The image may be auto-generated and while it's generated, the image in > `ImageIcon` remains `null`; when the image is read the app calls > `ImageIcon.setImage` to the set now available image and *expects the > description being preserved*. > Now .. what should happen to an existing description when you set a new image > ? > > Apps can call setDescription() but in what order ? > > The only thing I can say here is that I think if the image is null we > probably should clear the description. Nothing should happen to the description. These are two fields which can be changed independently now, why would we enforce an order on method calls? Changing the image shouldn't change the description; similarly, changing description doesn't change the image. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/25767#discussion_r2156641174