Skip to content

Commit e507766

Browse files
committed
8361610: Avoid wasted work in ImageIcon(Image) for setting description
Reviewed-by: kizune, aivanov
1 parent 21efd25 commit e507766

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/java.desktop/share/classes/javax/swing/ImageIcon.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -209,8 +209,10 @@ public ImageIcon (URL location) {
209209
* @param description a brief textual description of the image
210210
*/
211211
public ImageIcon(Image image, String description) {
212-
this(image);
212+
this.image = image;
213213
this.description = description;
214+
215+
loadImage(image);
214216
}
215217

216218
/**
@@ -222,12 +224,17 @@ public ImageIcon(Image image, String description) {
222224
* @see java.awt.Image#getProperty
223225
*/
224226
public ImageIcon (Image image) {
225-
this.image = image;
226-
Object o = image.getProperty("comment", imageObserver);
227-
if (o instanceof String) {
228-
description = (String) o;
229-
}
230-
loadImage(image);
227+
this(image, getImageComment(image));
228+
}
229+
230+
/**
231+
* @return the {@code "comment"} property of the image
232+
* if the value of the property is a sting}
233+
* @param image the image to get the {@code "comment"} property
234+
*/
235+
private static String getImageComment(Image image) {
236+
Object o = image.getProperty("comment", null);
237+
return (o instanceof String) ? (String) o : null;
231238
}
232239

233240
/**

0 commit comments

Comments
 (0)