Skip to content

Commit 81985d4

Browse files
committed
8358526: Clarify behavior of java.awt.HeadlessException constructed with no-args
Reviewed-by: aivanov, honkar
1 parent d627282 commit 81985d4

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/java.desktop/share/classes/java/awt/HeadlessException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public class HeadlessException extends UnsupportedOperationException {
4848
private static final long serialVersionUID = 167183644944358563L;
4949

5050
/**
51-
* Constructs new {@code HeadlessException} with empty message.
51+
* Constructs a new {@code HeadlessException} with {@code null} as its detail message.
52+
* The default headless message may replace {@code null} in some cases, as outlined below.
53+
* <p>
5254
* For such {@code HeadlessException} the default headless error message
5355
* may be auto-generated for some platforms.
5456
* The text of the default headless message may depend on
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
import java.awt.HeadlessException;
25+
26+
/*
27+
* @test 8358526
28+
* @summary Verify behaviour of no-args HeadlessException and getMessage
29+
* @run main/othervm -Djava.awt.headless=true HeadlessExceptionTest
30+
* @run main/othervm HeadlessExceptionTest
31+
*/
32+
33+
public class HeadlessExceptionTest {
34+
35+
public static void main (String[] args) {
36+
String nullmsg = new HeadlessException().getMessage();
37+
String emptymsg = new HeadlessException("").getMessage();
38+
System.out.println("nullmsg=" + nullmsg);
39+
System.out.println("emptymsg=" + emptymsg);
40+
if (nullmsg != null) {
41+
if ("".equals(nullmsg)) {
42+
throw new RuntimeException("empty message instead of null");
43+
}
44+
if (!nullmsg.equals(emptymsg)) {
45+
throw new RuntimeException("non-null messages differ");
46+
}
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)