To reproduce, run the attached test.
Select any text and press Caps Lock.
The following log shows up:
Feb 28, 2024 6:09:24 PM com.sun.javafx.webkit.InputMethodClientImpl callOnEventThread
SEVERE: InputMethodClientImpl java.util.concurrent.ExecutionException: java.lang.NullPointerException: Cannot invoke "String.substring(int, int)" because the return value of "com.sun.webkit.WebPage.getClientCommittedText()" is null
Feb 28, 2024 6:09:24 PM com.sun.javafx.webkit.InputMethodClientImpl callOnEventThread
SEVERE: InputMethodClientImpl java.util.concurrent.ExecutionException: java.lang.NullPointerException: Cannot invoke "String.substring(int, int)" because the return value of "com.sun.webkit.WebPage.getClientCommittedText()" is null
This log happens running any JavaFX version that includes the fix from JDK-8322703 (starting 22-ea+26 or 23-ea+1).
With lower JavaFX versions, the full stacktrace is:
java.lang.reflect.InvocationTargetException
at java.desktop/sun.lwawt.macosx.LWCToolkit.checkException(LWCToolkit.java:766)
at java.desktop/sun.lwawt.macosx.LWCToolkit.invokeAndWait(LWCToolkit.java:735)
at java.desktop/sun.lwawt.macosx.CInputMethod.attributedSubstringFromRange(CInputMethod.java:590)
Caused by: java.lang.NullPointerException: Cannot invoke "String.substring(int, int)" because the return value of "com.sun.webkit.WebPage.getClientCommittedText()" is null
at javafx.web@22-ea/com.sun.javafx.webkit.InputMethodClientImpl.getCommittedText(InputMethodClientImpl.java:185)
at javafx.graphics@22-ea/javafx.scene.Scene$InputMethodRequestsDelegate.getCommittedText(Scene.java:4216)
at javafx.swing@22-ea/javafx.embed.swing.InputMethodSupport$InputMethodRequestsAdapter.getCommittedText(InputMethodSupport.java:83)
at java.desktop/sun.awt.im.InputMethodContext.getCommittedText(InputMethodContext.java:302)
at java.desktop/sun.lwawt.macosx.CInputMethod$3.run(CInputMethod.java:602)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:308)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:744)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
java.lang.reflect.InvocationTargetException
at java.desktop/sun.lwawt.macosx.LWCToolkit.checkException(LWCToolkit.java:766)
at java.desktop/sun.lwawt.macosx.LWCToolkit.invokeAndWait(LWCToolkit.java:735)
at java.desktop/sun.lwawt.macosx.CInputMethod.attributedSubstringFromRange(CInputMethod.java:590)
Caused by: java.lang.NullPointerException: Cannot invoke "String.substring(int, int)" because the return value of "com.sun.webkit.WebPage.getClientCommittedText()" is null
at javafx.web@22-ea/com.sun.javafx.webkit.InputMethodClientImpl.getCommittedText(InputMethodClientImpl.java:185)
at javafx.graphics@22-ea/javafx.scene.Scene$InputMethodRequestsDelegate.getCommittedText(Scene.java:4216)
at javafx.swing@22-ea/javafx.embed.swing.InputMethodSupport$InputMethodRequestsAdapter.getCommittedText(InputMethodSupport.java:83)
at java.desktop/sun.awt.im.InputMethodContext.getCommittedText(InputMethodContext.java:302)
at java.desktop/sun.lwawt.macosx.CInputMethod$3.run(CInputMethod.java:602)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:308)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:744)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
After a quick inspection, it appears that the call to com.sun.webkit.WebPage.getClientCommittedText().substring() could use a null check to prevent the NPE.
It seems related to the issue JDK-8315495, that was closed as incomplete.