On Sun, 6 Sep 2026 15:22:36 GMT, Marius Hanl <[email protected]> wrote:

> Issue only exists in the Headless platform. Consider this test code:
> 
> 
> KeyCombination combination = KeyCombination.valueOf("shortcut+,");
> 
> KeyEvent event = new KeyEvent(KeyEvent.KEY_PRESSED, "s", "S", KeyCode.S, 
> false, true, false, false);
> boolean match = combination.match(event);
> 
> 
> What happens is that the KeyCombination is an instance of 
> `KeyCharacterCombination`.
> 
> `KeyCharacterCombination` is special, because in its `match` function, it 
> will call: 
> `Toolkit.getToolkit().getKeyCodeForChar(getCharacter(), code));`
> which will be delegated to the `HeadlessApplication`, which will throw an 
> `UnsupportedOperationException`.
> 
> Most of the time, the `KeyCombination` is not an instance of 
> `KeyCharacterCombination`, so this exception can only be reproduced with more 
> special combinations like in the example with the comma.
> 
> I used the implementation we also use in `Monocle`. Rechecked with the US 
> keyboard layout on a mac.
> 
> ---
> 
> Trivia: JabRef found this issue when changing their tests from Monocle to 
> Headless: [GHA 
> run](https://github.com/JabRef/jabref/actions/runs/34032443925/job/101484543433?pr=16850)
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

This pull request has now been integrated.

Changeset: 517a4de7
Author:    Marius Hanl <[email protected]>
URL:       
https://git.openjdk.org/jfx/commit/517a4de77257f531eb3615422ea6eb09e0aff88a
Stats:     209 lines in 2 files changed: 207 ins; 0 del; 2 mod

8391883: Headless Tests may throw Exception when matching a 
KeyCharacterCombination

Reviewed-by: angorya, mfox

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

PR: https://git.openjdk.org/jfx/pull/2297

Reply via email to