NPE in HighlightMethodUtil#isWeaker

已回答

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

0
Avatar
Permanently deleted user

Fixed. 

What kind of a crazy plugin do you write?

--

regards,

Alexey Kudravtsev

0
Avatar
Permanently deleted user

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

请先登录再写评论。