InvalidVirtualFileAccessException for existing file
Hi,
I'm sometimes getting the exception below from my implementation of
com.intellij.xml.XmlNSDescriptor. I have no idea how this can happen, a) because the mentioned file
is there and b) because my implementation of XmlNSDescriptor#getDependences() includes the PsiFile
that now chokes on getting its document.
If I check the file for isValid() and return null instead, all the tags in the XML file that refers
to this schema intermittently turn red, with a "cannot resolve ..." message. If I try to get the
file's document (just like IDEA's Schema support does), I'm getting this error, although it doesn't
happen reproducibly.
What's the trick to keep the file valid?
Please help, this is going to drive me nuts...
Thanks,
Sascha
com.intellij.openapi.vfs.InvalidVirtualFileAccessException: Accessing invalid virtual file:
jar://C:/Programme/IntelliJ
Selena/config/plugins/relax-ng/lib/relax-ng.jar!/org/intellij/plugins/relaxNG/resources/relaxng.rng
at com.intellij.openapi.vfs.newvfs.persistent.PersistentFS.c(PersistentFS.java:341)
at com.intellij.openapi.vfs.newvfs.persistent.PersistentFS.a(PersistentFS.java:18)
at com.intellij.openapi.vfs.newvfs.persistent.PersistentFS.d(PersistentFS.java:114)
at com.intellij.openapi.vfs.newvfs.persistent.PersistentFS.getInputStream(PersistentFS.java:133)
at com.intellij.openapi.vfs.newvfs.impl.VirtualFileImpl.getInputStream(VirtualFileImpl.java:9)
at com.intellij.openapi.vfs.newvfs.NewVirtualFile.contentsToByteArray(NewVirtualFile.java:41)
at com.intellij.openapi.fileEditor.impl.LoadTextUtil.loadText(LoadTextUtil.java:69)
at
com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.getDocument(FileDocumentManagerImpl.java:255)
at com.intellij.psi.SingleRootFileViewProvider.getDocument(SingleRootFileViewProvider.java:178)
at com.intellij.psi.impl.source.PsiFileImpl.loadTreeElement(PsiFileImpl.java:151)
at
com.intellij.psi.impl.RepositoryElementsManager.getOrFindTreeElement(RepositoryElementsManager.java:332)
at
com.intellij.psi.impl.source.SrcRepositoryPsiElement.calcTreeElement(SrcRepositoryPsiElement.java:67)
at com.intellij.psi.impl.source.xml.XmlFileImpl.getDocument(XmlFileImpl.java:17)
at
org.intellij.plugins.relaxNG.model.descriptors.RngNsDescriptor.getDeclaration(RngNsDescriptor.java:177)
at
org.intellij.plugins.relaxNG.model.descriptors.RngElementDescriptor.getDeclaration(RngElementDescriptor.java:194)
at com.intellij.psi.impl.source.xml.TagNameReference.resolve(TagNameReference.java:51)
at
com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.hasBadResolve(XmlHighlightVisitor.java:337)
at com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.a(XmlHighlightVisitor.java:231)
at com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.a(XmlHighlightVisitor.java:296)
at com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.a(XmlHighlightVisitor.java:77)
at
com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.visitXmlToken(XmlHighlightVisitor.java:148)
at com.intellij.psi.impl.source.xml.XmlTokenImpl.accept(XmlTokenImpl.java:6)
Please sign in to leave a comment.
Hello Sascha,
The VirtualFile pointing inside a .jar file can get invalidated when the
.jar file changes, even if the new .jar file still has the same path. You
should try to find the file by the same path again, and return null only
if that find attempt fails.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hello Dmitry,
Thanks for the reply. This would be easy if the .jar file wasn't the plugin's main jar
file which I'm pretty sure that it doesn't change while IDEA is running. In fact, it's
locked by the JVM. And it simply happens to frequently to be some weird coincidence.
And even if the file magically changed, why doesn't the dependency on it cause the
XmlNSDecriptor to be refreshed? I'd expect that I'm not asked for the declaration of an
outdated descriptor anyway.
Saving the path of the file seems like a possible workaround, but I think there must be
some other reason why this can happen in the first place.
Sascha
Hello Sascha,
>> The VirtualFile pointing inside a .jar file can get invalidated when
>> the .jar file changes, even if the new .jar file still has the same
>> path. You should try to find the file by the same path again, and
>> return null only if that find attempt fails.
>>
Your plugin .jar changes before you run IDEA, and at some point while IDEA
is running, the background refresh catches up with the changes and resynchronizes
the contents. Then the VirtualFile gets invalidated.
(No idea about XmlNSDescriptor stuff...)
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hello Dmitry,
Oh, that makes sense, but sounds kinda scary. Well, at least this means that it usually won't happen
too often. Thanks for the explanation, I would have never thought about that.
No problem, I'll stick with saving the file's path for the moment.
Sascha