RFR: 8358526: Clarify behavior of java.awt.HeadlessException constructed with no-args

Harshitha Onkar honkar at openjdk.org
Tue Jun 24 17:15:41 UTC 2025


On Tue, 24 Jun 2025 12:43:37 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

>> test/jdk/java/awt/Headless/HeadlessExceptionTest.java line 37:
>> 
>>> 35:     public static void main (String[] args) {
>>> 36:         String nullmsg = new HeadlessException().getMessage();
>>> 37:         String emptymsg = new HeadlessException("").getMessage();
>> 
>> @prrace I was thinking of a case which would actually throw HeadlessException when run with `Djava.awt.headless=true`  such as creating a frame or robot but the exception msg can be null or default message from GraphicsEnvironment so making it difficult to validate on different platforms. The current test works well to validate both empty and null message.
>
> Since this test is run on *headless* hosts, the default headless message will always be present on Linux, therefore `nullmsg` will not be `null`.
> 
> If the test is run on headful hosts, the message should be `null` and empty string correspondingly.
> 
> @honkar-jdk Do you suggest a test needs expanding to cover both cases where the default headless message is present or not?

@aivanov-jdk 

> Since this test is run on headless hosts, the default headless message will always be present on Linux, therefore nullmsg will not be null.

That is correct Alex. But since this default headless message is platform and GraphicsEnvironment specific, checking for specific message may not feasible. Did you mean checking for non-null msg (on headless)?
May be it is not as important as the cases already being tested in the reg test.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25881#discussion_r2164521752


More information about the client-libs-dev mailing list