void () { @Language("JAVA") String text = "class Foo { { @NotNull String foo; } }"; PsiFile file = configureByText(JavaFileType.INSTANCE, text); StubTree stubTree = ((PsiFileImpl)file).getStubTree(); assertNotNull(stubTree); PsiElement anno = stubTree.getPlainList().stream().map(StubElement::getPsi).filter(psiElement -> psiElement instanceof PsiAnnotation).findFirst().get(); SmartPsiElementPointer<PsiElement> pointer = createPointer(anno); assertNotNull(((PsiFileImpl)file).getStubTree()); //noinspection UnusedAssignment stubTree = null; //noinspection UnusedAssignment anno = null; gcPointerCache(pointer); insertString(file.getViewProvider().getDocument(), 0, " "); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); assertNotNull(pointer.getElement()); }