void () { PsiFile file = myFixture.configureByText("a.java", """ import lombok.val; import java.util.Optional; class Test { public void test() { val strOpt = Optional.of("1"); val intOptInferred<caret>Lambda = strOpt.map(str -> Integer.valueOf(str)); } } """); PsiLocalVariable var = PsiTreeUtil.getParentOfType(file.findElementAt(myFixture.getCaretOffset()), PsiLocalVariable.class); assertNotNull(var); PsiType typeBefore = var.getType(); assertNotNull(typeBefore); assertEquals("java.util.Optional<java.lang.Integer>", typeBefore.getCanonicalText(false)); myFixture.testHighlighting(false, false, false, file.getVirtualFile()); myFixture.type('2'); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); // this line will fail myFixture.testHighlighting(false, false, false, file.getVirtualFile()); assertTrue(var.isValid()); PsiType typeAfter = var.getType(); assertNotNull(typeAfter); assertEquals("java.util.Optional<java.lang.Integer>", typeAfter.getCanonicalText(false)); }