void () { Document document = createFreeThreadedDocument(); document.addDocumentListener(new PrioritizedDocumentListener() { @Override public int getPriority() { return 0; } @Override public void beforeDocumentChange(@NotNull DocumentEvent event) { throw new ProcessCanceledException(); } }); try { document.insertString(0, "a"); fail("PCE expected"); } catch (ProcessCanceledException ignored) { } getPsiDocumentManager().commitAllDocuments(); LeakHunter.checkLeak(getPsiDocumentManager(), Document.class, d -> d == document); }