void () { EditorFactory editorFactory = EditorFactory.getInstance(); Document document = editorFactory.createDocument("ab"); Editor editor = editorFactory.createEditor(document); try { editor.getCaretModel().moveToOffset(1); } finally { editorFactory.releaseEditor(editor); } runWriteCommand(() -> document.setText("cd")); // should run without throwing an exception }