void () { ThreadingAssertions.assertEventDispatchThread(); ModalityStateEx currentState = getCurrentModalityState(); if (currentState != ModalityState.nonModal()) { currentState.cancelAllEntities(); // let event queue pump once before trying to cancel next modal invokeLater(ModalityState.any(), Conditions.alwaysFalse(), () -> forceLeaveAllModals()); } }