On Wed, 26 Mar 2025 17:37:39 GMT, Martin Fox <m...@openjdk.org> wrote:

>> There is an undocumented limit on nesting calls to CFRunLoopRun (or the 
>> equivalent wrapper NSRunLoop methods). When the limit is hit the OS 
>> terminates the Java app. The situation arises when a JavaFX app creates too 
>> many nested event loops from within  Platform.runLater runnables.
>> 
>> This PR doesn't change the limit (which is 250+ nested loops) but it does 
>> throw an exception just before the limit is reached so a JavaFX developer 
>> will get a useful Java stack trace instead of an OS crash log.
>> 
>> On the Mac the nested event loop has two stages: first we ask the run loop 
>> to run, then we pull an event out and process it. A Platform.runLater 
>> runnable is executed in the first stage so if the runnable starts a new 
>> nested event loop the system will re-enter CFRunLoopRun. The same isn't true 
>> if an input event handler starts a new nested event loop; at that point 
>> we're in stage two and are past the call to CFRunLoopRun.
>
> Martin Fox has updated the pull request incrementally with two additional 
> commits since the last revision:
> 
>  - Set limit on nested event loop count to 200 which seems less arbitrary
>  - The max nested event loop limit is now platform-independent

modules/javafx.graphics/src/main/java/javafx/application/Platform.java line 279:

> 277:      * @since 25
> 278:      */
> 279:     public static final int MAX_NESTED_EVENT_LOOPS = 200;

I would rather not make this constant public.  This is essentially a safeguard 
measure, with the main purpose to prevent the crash and give the indication to 
the application developer that their program has an issue.  From this 
perspective, the actual number is not important and should not be codified as a 
public API (but definitely declared as a constant internally).

What do you think?

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

PR Review Comment: https://git.openjdk.org/jfx/pull/1741#discussion_r2014778827

Reply via email to