Why I get IndexNotReadyException ?
Answered
I have read
https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/openapi/project/IndexNotReadyException.java
documentation,I have tried DumbService#smartInvokeLater and DumbService#runReadActionInSmartMode,It does not work for me.
I am extend from FileBasedIndexExtension class,override the map method,inside map method ,i want to get method annotation.
My code looks like below:
PsiJavaFile psiFile = (PsiJavaFile) fileContent.getPsiFile();
PsiMethod[] methods = psiFile.getClasses()[0].getMethods();
for (PsiMethod method : methods) {
ann = method.getAnnotation(annName); // <- This line throw IndexNotReadyException
}
Please sign in to leave a comment.
You may not access anything outside of current file being indexed in your FileBasedIndexExtension. See https://www.jetbrains.org/intellij/sdk/docs/basics/indexing_and_psi_stubs/file_based_indexes.html
fileContent is not outside of current file ,fileContent is map function parameter.
public Map<String, ResourceElement> map(@NotNull FileContent fileContent) {PsiJavaFile psiFile = (PsiJavaFile) fileContent.getPsiFile();
PsiMethod[] methods = psiFile.getClasses()[0].getMethods();
for (PsiMethod method : methods) {
ann = method.getAnnotation(annName); // <- This line throw IndexNotReadyException
}
}
Please post full stacktrace
As can be seen in stacktrace, call to PsiMethod#getAnnotation() will need access to JavaFullClassNameIndex which is forbidden at this point.