NPE in HighlightMethodUtil#isWeaker

Answered

Introduction. I am very surprised that such an error was not there before. About a year already working plug and there was no error.

 

In if statement for plugins with implicit access modifiers this code produce NPE.
Our modifier list has protected modifier on PsiMethod without explicit keyword.

Code

       if (modifierList.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) {
textRange = method.getNameIdentifier().getTextRange();
}
else {
PsiElement keyword = PsiUtil.findModifierInList(modifierList, accessModifier);
textRange = keyword.getTextRange(); // here NPE
}
}


java.lang.NullPointerException
 at com.intellij.codeInsight.daemon.impl.analysis.HighlightMethodUtil.isWeaker(HighlightMethodUtil.java:113)
 at com.intellij.codeInsight.daemon.impl.analysis.HighlightMethodUtil.checkMethodWeakerPrivileges(HighlightMethodUtil.java:91)
 at com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl.visitModifierList(HighlightVisitorImpl.java:888)
 at com.intellij.psi.impl.source.PsiModifierListImpl.accept(PsiModifierListImpl.java:307)
 at com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl.visit(HighlightVisitorImpl.java:143)
 at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.runVisitors(GeneralHighlightingPass.java:334)
Can you fix this?
Like this:

Code
       if (modifierList.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) {
textRange = method.getNameIdentifier().getTextRange();
}
else {
PsiElement keyword = PsiUtil.findModifierInList(modifierList, accessModifier);
textRange = keyword == null ? method.getNameIdentifier().getTextRange() : keyword.getTextRange(); // here NPE
}
}

Or something else

2 comments
Comment actions Permalink

Fixed. 

What kind of a crazy plugin do you write?

--

regards,

Alexey Kudravtsev

0
Comment actions Permalink

Somewhat similar to Lombok. The plugin for java like language.

Thanks.

 

PS.  remove bug report? 

https://youtrack.jetbrains.com/issue/IJSDK-182

 

regards,

Alexandr Zhelezniak

0

Please sign in to leave a comment.