private static void cleanupQueueForModal(@NotNull final Object modalEntity) {
   synchronized (LOCK) {
     for (Iterator<RunnableInfo> iterator = ourQueue.iterator(); iterator.hasNext(); ) {
       RunnableInfo runnableInfo = iterator.next();
       if (runnableInfo.modalityState instanceof ModalityStateEx) {
         ModalityStateEx stateEx = (ModalityStateEx) runnableInfo.modalityState;
         if (stateEx.contains(modalEntity)) {
           ourForcedFlushQueue.add(runnableInfo);
           iterator.remove();
         }
       }
     }
   }
 }