public static boolean setExceptionalThreadWithReadAccessFlag(boolean flag) {
   boolean old = isExceptionalThreadWithReadAccess();
   if (flag) {
     exceptionalThreadWithReadAccessFlag.set(Boolean.TRUE);
   } else {
     exceptionalThreadWithReadAccessFlag.remove();
   }
   return old;
 }
  public void runEdtSafeAction(@NotNull Runnable runnable) {
    Integer value = ourEdtSafe.get();
    if (value == null) {
      value = Integer.valueOf(0);
    }

    ourEdtSafe.set(value + 1);

    try {
      runnable.run();
    } finally {
      int newValue = ourEdtSafe.get() - 1;
      ourEdtSafe.set(newValue >= 1 ? newValue : null);
    }
  }
  private static void assertIsDispatchThread(String message) {
    if (ShutDownTracker.isShutdownHookRunning()) return;
    final Thread currentThread = Thread.currentThread();
    if (ourDispatchThread == currentThread) return;

    if (EventQueue.isDispatchThread()) {
      ourDispatchThread = currentThread;
    }
    if (ourDispatchThread == currentThread) return;

    Integer safeCounter = ourEdtSafe.get();
    if (safeCounter != null && safeCounter > 0) return;

    LOG.error(
        message,
        "Current thread: " + describe(Thread.currentThread()),
        "Our dispatch thread:" + describe(ourDispatchThread),
        "SystemEventQueueThread: " + describe(getEventQueueThread()));
  }
 private static boolean isExceptionalThreadWithReadAccess() {
   Boolean flag = exceptionalThreadWithReadAccessFlag.get();
   return flag == Boolean.TRUE;
 }