Repository navigation
NullReferenceException getting URI absolute path in PythonModule.Definition #1018
Description
Activity
AlexanderSher commented
on Apr 26, 2019 ContributorMore actionsUrican be null only forSentinelModule.AlexanderSher commented
on Apr 26, 2019 ContributorMore actionsDo you have repro steps?
jakebailey commented
on Apr 26, 2019 MemberAuthorMore actionsFor
PythonModule, you mean? I wonder where the null is coming from, then. Even for untitled files, there will be a URI. Without line information I've been assuming that the URI is null, but it might be a member (Uri.LocalPath?).I have no repro for this, unfortunately; these are pulled from telemetry.
AlexanderSher commented
on Apr 26, 2019 ContributorMore actionsLocalPathdoesn't returnnull. IfUriis null for any other type thanSentinelModule, then we have a bug in some other place.MikhailArkhipov commented
on May 1, 2019 More actionsFor
SentineltheModule?.Analysis.Astwould be null since it has empty analysis. Anyway, I'll add extra checks anyway.AlexanderSher commented
on May 1, 2019 ContributorMore actionsHow is it possible to get
SentinelinFindDefinition?MikhailArkhipov commented
on May 1, 2019 More actionsUnresolved import?
AlexanderSher commented
on May 1, 2019 ContributorMore actionsFindDefinitionchecksanalysis?.Astat the very beginningif (analysis?.Ast == null) { return null; }
So it won't proceed for unresolved import.
MikhailArkhipov commented
on May 1, 2019 More actionsBunch of code checks
FilePathfor nulls so I guess there could be cases. Also,SpecializedModule. Expublic IPythonModule SpecializeModule(string name, Func<string, IPythonModule> specializationConstructor) { var import = CurrentPathResolver.GetModuleImportFromModuleName(name); var module = specializationConstructor(import?.ModulePath); _specialized[name] = module; return module; }
AlexanderSher commented
on May 1, 2019 ContributorMore actionsFilePathcan be null,Urican't.
SpecializedModuleis abstract, its only derived class isTypingModule. So that would requireTypingModuleto be created with null or invalid path. Is it possible?MikhailArkhipov commented
on May 1, 2019 More actionsTechnically yes
var import = CurrentPathResolver.GetModuleImportFromModuleName(name); var module = specializationConstructor(import?.ModulePath);such as we didn't find
typingMikhailArkhipov commented
on May 1, 2019 More actionsAnd in
PythonVariableModulepublic Uri Uri => Module?.Uri;
AlexanderSher commented
on May 1, 2019 ContributorMore actionsThen we should probably fail in this place: if module path isn't found, there is no reason to specialize it.
MikhailArkhipov commented
on May 1, 2019 More actionsBut this
public PythonVariableModule(string name, IPythonInterpreter interpreter) : base(PythonMemberType.Module) { Name = name; Interpreter = interpreter; SetDeclaringModule(this); }
called from
private PythonVariableModule GetOrCreateVariableModule(in string fullName, in PythonVariableModule parentModule, in string memberName) { if (_variableModules.TryGetValue(fullName, out var variableModule)) { return variableModule; } variableModule = new PythonVariableModule(fullName, Interpreter);
creates module with no
Moduleand hence no URIAlexanderSher commented
on May 1, 2019 ContributorMore actionsPythonVariableModulewithoutModulemeans that it is actually a package. So we shouldn't get into searching for module members in first place.
Fix is likely one of:
Uri?.ToAbsolutePath();LocationInfo.FilePathis only ever used for comparison and is allowed to be null.PythonModule.FilePathinstead of convertingUri.