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 !

0
5 comments

Hi Gaëtan,

Please provide us with the full stacktrace.

0

Here it is (sorry for not anticipating that)

update failed for AnAction(com.intellij.codeInsight.documentation.actions.ShowQuickDocInfoAction, id=QuickJavaDoc) with text=Quick Documentation

java.lang.NullPointerException
    at groovy.lang.MetaClassImpl.getSuperMethodWithCaching(MetaClassImpl.java:1438)
    at groovy.lang.MetaClassImpl.getMethodWithCaching(MetaClassImpl.java:1376)
    at groovy.lang.MetaClassImpl.getMetaMethod(MetaClassImpl.java:1280)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1132)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:144)
    at fr.nereide.documentation.OfbizOverrideDocumentationProvider.getCustomDocumentationElement(OfbizOverrideDocumentationProvider.groovy:33)
    at com.intellij.lang.documentation.CompositeDocumentationProvider.getCustomDocumentationElement(CompositeDocumentationProvider.java:291)
    at com.intellij.codeInsight.documentation.DocumentationManager.customElement(DocumentationManager.java:994)
    at com.intellij.codeInsight.documentation.DocumentationManager.doFindTargetElementAtOffset(DocumentationManager.java:972)
    at com.intellij.codeInsight.documentation.DocumentationManager.findTargetElementAtOffset(DocumentationManager.java:958)
    at com.intellij.codeInsight.documentation.DocumentationManager.findTargetElementAndContext(DocumentationManager.java:900)
    at com.intellij.lang.documentation.ide.impl.IdeDocumentationTargetProviderImpl.documentationTargets(IdeDocumentationTargetProviderImpl.kt:43)
    at com.intellij.lang.documentation.ide.actions.ActionsKt.targetsFromEditor(actions.kt:110)
    at com.intellij.lang.documentation.ide.actions.ActionsKt.documentationTargetsInner(actions.kt:78)
    at com.intellij.lang.documentation.ide.actions.ActionsKt.documentationTargets(actions.kt:62)
    at com.intellij.codeInsight.documentation.actions.ShowQuickDocInfoAction.update(ShowQuickDocInfoAction.kt:34)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.lambda$performDumbAwareUpdate$0(ActionUtil.java:131)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareUpdate(ActionUtil.java:145)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.doUpdate(ActionUpdater.java:639)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$updateActionReal$4(ActionUpdater.java:125)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.callAction(ActionUpdater.java:175)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.updateActionReal(ActionUpdater.java:126)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$new$0(ActionUpdater.java:111)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.update(ActionUpdater.java:628)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.expandGroupChild(ActionUpdater.java:472)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$doExpandActionGroup$20(ActionUpdater.java:451)
    at com.intellij.util.containers.ContainerUtil.concat(ContainerUtil.java:1400)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.doExpandActionGroup(ActionUpdater.java:451)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.expandGroupChild(ActionUpdater.java:529)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$doExpandActionGroup$20(ActionUpdater.java:451)
    at com.intellij.util.containers.ContainerUtil.concat(ContainerUtil.java:1400)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.doExpandActionGroup(ActionUpdater.java:451)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.expandActionGroup(ActionUpdater.java:259)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$expandActionGroupAsync$12(ActionUpdater.java:320)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$expandActionGroupAsync$14(ActionUpdater.java:343)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1152)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$expandActionGroupAsync$15(ActionUpdater.java:343)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runActionAndCancelBeforeWrite(ProgressIndicatorUtils.java:158)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$expandActionGroupAsync$16(ActionUpdater.java:339)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:189)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:608)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:683)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:639)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:607)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:176)
    at com.intellij.openapi.progress.util.BackgroundTaskUtil.runUnderDisposeAwareIndicator(BackgroundTaskUtil.java:365)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$expandActionGroupAsync$17(ActionUpdater.java:338)
    at com.intellij.util.concurrency.BoundedTaskExecutor.doRun(BoundedTaskExecutor.java:241)
    at com.intellij.util.concurrency.BoundedTaskExecutor.access$200(BoundedTaskExecutor.java:31)
    at com.intellij.util.concurrency.BoundedTaskExecutor$1.execute(BoundedTaskExecutor.java:214)
    at com.intellij.util.ConcurrencyUtil.runUnderThreadName(ConcurrencyUtil.java:212)
    at com.intellij.util.concurrency.BoundedTaskExecutor$1.run(BoundedTaskExecutor.java:203)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
    at java.base/java.lang.Thread.run(Thread.java:829)
0

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.

0

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.

0

Made it work by returning null instead of super method.

Thanks anyway !

0

Please sign in to leave a comment.