JDK-8211304 : [macOS] Crash on focus loss from dialog on macOS 10.14 Mojave
  • Type: Bug
  • Component: javafx
  • Sub-Component: window-toolkit
  • Affected Version: 8u181,openjfx11
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86
  • Submitted: 2018-09-26
  • Updated: 2020-01-31
  • Resolved: 2018-11-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 Other
8u201Fixed openjdk8u212Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
macOS 10.14 Mojave
Java 8u181


A DESCRIPTION OF THE PROBLEM :
If a JavaFX application is showing a dialog and switch to another application is crashes.

Reproduced on multiple machines. Updating to 10.14.1 Beta did not resolve the issue.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached program, click the "Say 'Hello World'" button to show the in for dialog. Now switch focus to another application (I'm using Safari for this), the back to the Java app and it will have vanished.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It to be there.
ACTUAL -
Crash, with the following:

2018-09-26 13:19:26.950 java[1389:16558] unrecognized type is 4294967295
2018-09-26 13:19:26.950 java[1389:16558] *** Assertion failure in -[NSEvent _initWithCGEvent:eventRef:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1671/AppKit.subproj/NSEvent.m:1969
2018-09-26 13:19:26.951 java[1389:16558] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: _type > 0 && _type <= kCGSLastEventType'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff4593b43d __exceptionPreprocess + 256
	1   libobjc.A.dylib                     0x00007fff71848720 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff4595608e +[NSException raise:format:arguments:] + 98
	3   Foundation                          0x00007fff47cf255d -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
	4   AppKit                              0x00007fff42de1acd -[NSEvent _initWithCGEvent:eventRef:] + 3272
	5   AppKit                              0x00007fff43135188 +[NSEvent eventWithCGEvent:] + 120
	6   libglass.dylib                      0x000000010c9af17b listenTouchEvents + 59
	7   SkyLight                            0x00007fff6b906782 _ZL19processEventTapDataPvjjjPhj + 148
	8   SkyLight                            0x00007fff6b805bb2 _XPostEventTapData + 278
	9   SkyLight                            0x00007fff6b906690 _ZL22eventTapMessageHandlerP12__CFMachPortPvlS1_ + 132
	10  CoreFoundation                      0x00007fff45899a5b __CFMachPortPerform + 246
	11  CoreFoundation                      0x00007fff45899959 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
	12  CoreFoundation                      0x00007fff458998b7 __CFRunLoopDoSource1 + 527
	13  CoreFoundation                      0x00007fff45881945 __CFRunLoopRun + 2574
	14  CoreFoundation                      0x00007fff45880ce4 CFRunLoopRunSpecific + 463
	15  Foundation                          0x00007fff47be15da -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 280
	16  libglass.dylib                      0x000000010c99cad5 +[GlassApplication enterNestedEventLoopWithEnv:] + 165
	17  libglass.dylib                      0x000000010c99d51a Java_com_sun_glass_ui_mac_MacApplication__1enterNestedEventLoopImpl + 74
	18  ???                                 0x000000010e01d667 0x0 + 4529968743
)
libc++abi.dylib: terminating with uncaught exception of type NSException


---------- BEGIN SOURCE ----------
package helloworld;
 
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
 
public class HelloWorld extends Application {
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>()
        {
 
            @Override
            public void handle(ActionEvent event) 
            {
                Alert alert = new Alert(AlertType.INFORMATION);
                alert.setTitle("Hellow World!");
                alert.setHeaderText("Hellow World!");
                alert.setContentText("Hellow World!");
               alert.showAndWait();                
            }
        });
        
        final StackPane root = new StackPane();
        root.getChildren().add(btn);
        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Close dialogs before giving focus to another application.

FREQUENCY : always



Comments
[~cstanford] Yes, this was approved by [~jvos] to push to 11-dev for the 11.0.2 release.
08-11-2018

It would be great if it could be back ported to jfx 11 as well
07-11-2018

Given the severity of this bug (FX apps are unusable on macOS 10.14 out of the box), this is approved for backporting to 8u-dev. The patch applies cleanly with no changes to 8u-dev (after adjusting the path to the file), so no additional code review is needed. I can confirm that this fixes the bug on JDK 8u as well.
07-11-2018

Changeset: e864311d97e6 Author: kcr Date: 2018-11-07 11:46 -0800 URL: http://hg.openjdk.java.net/openjfx/jfx-dev/rt/rev/e864311d97e6 8211304: [macOS] Crash on focus loss from dialog on macOS 10.14 Mojave Reviewed-by: arajkumar, mbilla
07-11-2018

Code review on Github: https://github.com/javafxports/openjdk-jfx/pull/271
06-11-2018

This crash is caused by a latent bug in GlassTouches.m. There are two related problems in glass' CGEventTapCallBack method, listenTouchEvents. 1) A CGEventTapCallBack method can receive two out of band values, kCGEventTapDisabledByTimeout and kCGEventTapDisabledByUserInput, and we are only handling the first of them. 2) We unconditionally call NSEvent::eventWithCGEvent without checking that the event in question is the right type, NSEventTypeGesture in our case. The fix is to check for kCGEventTapDisabledByUserInput in addition to kCGEventTapDisabledByTimeout and re-enable the event tap when either out of band value occurs (a Google search shows that this is a common thing to do). This is necessary so that once we regain focus to the window we continue to get touch events. In order to bullet-proof the code, I will also check for type == NSEventTypeGesture before calling NSEvent::eventWithCGEvent
06-11-2018

I can reproduce this on a local system. We will need to fix in in jfx-dev mainline for openjfx12, and also backport it to JDK 8u.
03-11-2018

Additional Information from Submitter of JDK-8211982: Is there any analysis on the underlying JavaFX bug as to why this manual workaround "fixes" the issue? Is the JDK/JavaFX doing CGEvent "tapping"? Is there any plan for a fix in JavaFX 8?
12-10-2018

I can confirm that this occurs on openjfx 11 and macOS 10.14
11-10-2018

Additional Information from Submitter of JDK-8211982: ---------------------------------------------------- Manual Work around for Mac OS 10.14: System Preferences > Security & Privacy > Accessibility > Add the failing application to the list.
11-10-2018

[~pmangal] Is this seen on openjfx 11 as well ?
04-10-2018

Additional Information from Submitter: ---------------------------------------------- After further debugging we've found: libglass.dylib was crashing in listenTouchEvents in the call to [NSEvent eventWithCGEvent:event] This was due to it not expecting an kCGEventTapDisabledByUserInput event which was sent to it when alt tabbing back and forth between the app. This happened whenever we had an Alert that was opened with the Alert.showAndWait method. Alert.show did not suffer from this issue, although we still got an Assertion logged out (*** Assertion failure in -[NSEvent _initWithCGEvent:eventRef:]) on the console. The only difference between Alert.show and Alert.showAndWait was that the implementation of Alert.showAndWait seemed to spawn off a JavaFX nestedLoop. Our workaround was to recompile libglass.dylib and modify the line: if (type == kCGEventTapDisabledByTimeout) To: if (type == kCGEventTapDisabledByTimeout || type == kCGEventTapDisabledByUserInput) Our assumption here is that this event wasn't sent by any previous version of macOS, and much like the workaround for kCGEventTapDisabledByTimeout one is also needed for kCGEventTapDisabledByUserInput. ----------------------------------------------
04-10-2018

Could not reproduce the issue in macOS High Sierra 10.13.5 using JDK 8u181. Looks duplicate of JDK-8211137.
01-10-2018

Additional information from Submitter: ----------------------------------------------------- Apologies if this wasn't clear from my initial report. This works correctly in macOS High Sierra 10.13.6 and previous releases. This crash only happens in macOS 10.14 Mojave and 10.14.1 Beta 1. This is a major issue - since Mojave was released last week we've have lots of reports of this. Any user out there running a JavaFX application that uses dialogs will start getting these crashes when they upgrade to Mojave. I think it's wrong to dup this against JDK-8211137 - this happens in Java 8 and only on 10.14+ --------------------------------------------------
01-10-2018