Odd test failures with recent IDEA builds

With recent builds of IDEA (12.1 EAP Series), some of my plugin tests started failing due to PsiFileImpl.isValid() returning false.  I've worked around the failures, but I was left wondering if my workaround simply hides a real problem.  Here's the background:

The problematic tests all extended this test, and I tracked the problems down to the call to TemplateDataLanguageMappings.  That call is creating a new instance of the file it is given, which results in PsiFile.isPsiUpToDate() evaluating to false (which then results in PsiFileImpl.isValid() being false).

I've worked around the issue by fetching the file out of the project after the call to TemplateDataLanguageMappings (see diff here), but it feels like that shouldn't be necessary... so I was wondering:

  • Could there be a flaw in my test that lead to this?
  • Or is this indicative of a bug introduced in IDEA?  
  • Or is this totally OK and grabbing a fresh copy of a file from the project before manipulating it is a best practice?

Hope that all makes sense!
Comment actions Permalink

This call effectively changes the language used to parse the file, which can make the old PsiFile (parsed according to the old language) invalid. Fetching a new PsiFile from a VirtualFile is an acceptable fix for the issue.

Comment actions Permalink

Totally makes sense.  Guess it was just luck that it was working in previous versions.  Thanks Dmitry!


Please sign in to leave a comment.