Fix NPE in ProducerUtils#getTestClass
PsiLocation#fromPsiElement can return null even though it's not
annotated as being For our code path, that method might
return null if the passed PsiElement is not valid anymore (which is
a corner case users shouldn't run often into).
Fixes
@@ -95,7 +95,8 @@ public class ProducerUtils {
@Nullable
public static PsiClass getTestClass(final PsiElement element) {
- return getTestClass(PsiLocation.fromPsiElement(element));
+ Location<PsiElement> location = PsiLocation.fromPsiElement(element);
+ return location != null ? getTestClass(location) : null;
}
/** Same as {@link JUnitUtil#getTestClass}, but handles classes outside the project. */
