NPE in getCustomDocumentationElement
Answered
Hi guys.
I'm working on documentation in custom framework, so far so good except for one point.
I get a NPE inside methode getCustomDocumentationElement. And i don't understand because none of the parameters are null :
class OfbizOverrideDocumentationProvider extends OfbizCommonDocumentationProvider {
@Override
PsiElement getCustomDocumentationElement(@NotNull Editor editor, @NotNull PsiFile file, @Nullable PsiElement contextElement, int targetOffset) {
PsiElement xmlAttr = PsiTreeUtil.getParentOfType(contextElement, XmlAttribute.class)
if (xmlAttr) {
if (OfbizPatterns.XML.SERVICE_DEF_CALL.accepts(xmlAttr)) {
PsiElement xmlAttrValue = PsiTreeUtil.getChildOfType(xmlAttr, XmlAttributeValue)
return xmlAttrValue ? resolveService(xmlAttrValue) : null
}
}
if (OfbizPatterns.JAVA.SERVICE_CALL.accepts(contextElement)) {
return resolveService(PsiTreeUtil.getParentOfType(contextElement, PsiLiteralExpression.class))
}
// Here is the NPE
return super.getCustomDocumentationElement(editor, file, contextElement, targetOffset)
}
private static PsiElement resolveService(XmlAttributeValue attr) {
ServiceReference service = new ServiceReference(attr, true)
return service.resolve()
}
private static PsiElement resolveService(PsiLiteralExpression expr) {
ServiceJavaReference service = new ServiceJavaReference(expr, true)
return service.resolve()
}
}
And the NPE breaks at the return super, even if none of the parameters is null.
Is this a known issue ? or did i make a mistake ?
Thanks in advance !
Please sign in to leave a comment.
Hi Gaëtan,
Please provide us with the full stacktrace.
Here it is (sorry for not anticipating that)
It seems that this stacktrace doesn't match the code. OfbizOverrideDocumentationProvider calls super.getCustomDocumentationElement() and it is not present in the stacktrace. Are you sure this is the place where it is thrown?
Also, classes from the rest of the stacktrace come from Groovy language code and are out of IntelliJ Platform scope, so I'm afraid I can't help you with that. I suggest debugging this code to see what is null and why.
Well from what i see yes it comes from this line. I'm confused. Nothing seems null here.
THe idea in my head would be that this documentation provider gets called first no matter the case, and after that if no case matches what i wand, then call super and go to standard.
Made it work by returning null instead of super method.
Thanks anyway !