From cf7140322e0c61d07d991a7a29afb205c1764a8c Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Fri, 3 Feb 2017 05:16:42 +0300 Subject: [PATCH] Fix NPE: PsiElement.containingFile can be null if file is directory * In Django we resolve package (directory) sometimes * Anyway this method is nullable according to doc, we make code safer by checking it for null --- .../src/com/jetbrains/python/psi/resolve/PyResolveImportUtil.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/psi/resolve/PyResolveImportUtil.kt b/python/src/com/jetbrains/python/psi/resolve/PyResolveImportUtil.kt index bada647c2bb9..f09c182811a2 100644 --- a/python/src/com/jetbrains/python/psi/resolve/PyResolveImportUtil.kt +++ b/python/src/com/jetbrains/python/psi/resolve/PyResolveImportUtil.kt @@ -128,7 +128,7 @@ fun resolveModuleAt(name: QualifiedName, directory: PsiDirectory?, context: PyQu * Creates a [PyQualifiedNameResolveContext] from a [foothold] element. */ fun fromFoothold(foothold: PsiElement): PyQualifiedNameResolveContext { - val module = ModuleUtilCore.findModuleForPsiElement(foothold.containingFile) + val module = ModuleUtilCore.findModuleForPsiElement(foothold.containingFile ?: foothold) return PyQualifiedNameResolveContextImpl(foothold.manager, module, foothold, PythonSdkType.findPythonSdk(module)) }