Skip to content

Commit bc66d3e

Browse files
committed
8370467: BorderFactory.createBevelBorder and createSoftBevelBorder throws NPE for null highlight and shadow
Reviewed-by: aivanov, tr, honkar
1 parent d2571ea commit bc66d3e

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

src/java.desktop/share/classes/javax/swing/border/BevelBorder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, 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
@@ -95,7 +95,9 @@ public BevelBorder(int bevelType) {
9595
* @param shadow the color to use for the bevel shadow
9696
*/
9797
public BevelBorder(int bevelType, Color highlight, Color shadow) {
98-
this(bevelType, highlight.brighter(), highlight, shadow, shadow.brighter());
98+
this(bevelType,
99+
(highlight != null) ? highlight.brighter() : null, highlight,
100+
shadow, (shadow != null) ? shadow.brighter() : null);
99101
}
100102

101103
/**
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 8370467
27+
* @summary Verifies createBevelBorder and createSoftBevelBorder does not throw NPE
28+
* @run main TestBevelBorderParam
29+
*/
30+
31+
import javax.swing.BorderFactory;
32+
import javax.swing.border.BevelBorder;
33+
34+
public class TestBevelBorderParam {
35+
36+
public static void main(String[] args) throws Exception {
37+
StringBuilder str = new StringBuilder();
38+
39+
try {
40+
BorderFactory.createBevelBorder(BevelBorder.RAISED, null, null);
41+
} catch (NullPointerException ex) {
42+
str.append("\n");
43+
str.append("BorderFactory.createBevelBorder throws NPE for null highlight and shadow");
44+
}
45+
46+
try {
47+
BorderFactory.createSoftBevelBorder(BevelBorder.RAISED, null, null);
48+
} catch (NullPointerException e) {
49+
str.append("\n");
50+
str.append("BorderFactory.createSoftBevelBorder throws NPE for null highlight and shadow");
51+
}
52+
53+
try {
54+
new BevelBorder(BevelBorder.RAISED, null, null);
55+
} catch (NullPointerException ex) {
56+
str.append("\n");
57+
str.append("BevelBorder constructor throws NPE for null highlight and shadow");
58+
}
59+
60+
if (str.length() != 0) {
61+
throw new RuntimeException(str.toString());
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)