void () { final MyElement element = createElement("<a><child-element/><child-element><child/></child-element></a>"); final MyElement parent = element.getChildElements().get(1); final MyElement child = parent.getChild(); final MyElement copy = child.createStableCopy(); WriteCommandAction.runWriteCommandAction(getProject(), () -> { parent.undefine(); element.addChildElement().getChild().ensureXmlElementExists(); }); assertFalse(child.isValid()); assertTrue(copy.isValid()); }