RunResult<T> () { final RunResult<T> result = new RunResult<>(this); Application application = ApplicationManager.getApplication(); if (application.isWriteIntentLockAcquired()) { try(AccessToken ignored = ApplicationManager.getApplication().acquireWriteActionLock(getClass())) { result.run(); } return result; } if (application.isReadAccessAllowed()) { LOG.error("Must not start write action from within read action in the other thread - deadlock is coming"); } WriteThread.invokeAndWait(() -> { try(AccessToken ignored = ApplicationManager.getApplication().acquireWriteActionLock(getClass())){ result.run(); } }); result.throwException(); return result; }