Skip to content

Commit 8341060

Browse files
authored
Merge bcdef9b into 2000551
2 parents 2000551 + bcdef9b commit 8341060

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
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
@@ -367,9 +367,13 @@ public Image getImage() {
367367

368368
/**
369369
* Sets the image displayed by this icon.
370+
* A null image is ignored.
370371
* @param image the image
371372
*/
372373
public void setImage(Image image) {
374+
if (image == null) {
375+
return;
376+
}
373377
this.image = image;
374378
loadImage(image);
375379
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8159055
27+
* @summary Verifies ImageIcon.setImage handles null parameter
28+
* @run main ImageIconNullImageTest
29+
*/
30+
31+
import javax.swing.ImageIcon;
32+
import javax.swing.SwingUtilities;
33+
34+
public class ImageIconNullImageTest {
35+
36+
public static void main(String[] args) throws Exception {
37+
SwingUtilities.invokeAndWait(() -> {
38+
ImageIcon icon = new ImageIcon();
39+
icon.setImage(null);
40+
});
41+
}
42+
}

0 commit comments

Comments
 (0)