rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.91k stars 299 forks source link

Opening Code Inspections window throws NullReferenceException #676

Closed daFreeMan closed 9 years ago

daFreeMan commented 9 years ago

When I open an existing Excel workbook, then open the Code Inspections window in RD, I get the following NRE:

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at Rubberduck.Parsing.Symbols.Declarations.<>c__DisplayClass4.<FindMembers>b__3(Declaration declaration) in c:\Users\Mathieu\Source\Repos\Rubberduck\Rubberduck.Parsing\Symbols\Declarations.cs:line 56
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at Rubberduck.Parsing.Symbols.IdentifierReferenceResolver.ResolveInternal(DictionaryCallStmtContext fieldCall, Declaration parent, Boolean hasExplicitLetStatement, Boolean isAssignmentTarget) in c:\Users\Mathieu\Source\Repos\Rubberduck\Rubberduck.Parsing\Symbols\IdentifierReferenceResolver.cs:line 327
   at Rubberduck.Parsing.Symbols.IdentifierReferenceResolver.ResolveInternal(ParserRuleContext callSiteContext, Declaration localScope, ContextAccessorType accessorType, DictionaryCallStmtContext fieldCall, Boolean hasExplicitLetStatement, Boolean isAssignmentTarget) in c:\Users\Mathieu\Source\Repos\Rubberduck\Rubberduck.Parsing\Symbols\IdentifierReferenceResolver.cs:line 297
   at Rubberduck.Parsing.Symbols.IdentifierReferenceListener.EnterICS_S_VariableOrProcedureCall(ICS_S_VariableOrProcedureCallContext context) in c:\Users\Mathieu\Source\Repos\Rubberduck\Rubberduck.Parsing\Symbols\IdentifierReferenceListener.cs:line 89
   at Rubberduck.Parsing.Grammar.VBAParser.ICS_S_VariableOrProcedureCallContext.EnterRule(IParseTreeListener listener) in c:\Users\Mathieu\Source\Repos\Rubberduck\Rubberduck.Parsing\Grammar\VBAParser.cs:line 12715
   at Antlr4.Runtime.Tree.ParseTreeWalker.EnterRule(IParseTreeListener listener, IRuleNode r)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Antlr4.Runtime.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t)
   at Rubberduck.Parsing.VBProjectParseResult.Resolve() in c:\Users\Mathieu\Source\Repos\Rubberduck\Rubberduck.Parsing\VBProjectParseResult.cs:line 56
   at Rubberduck.Parsing.VBA.RubberduckParser.Parse(VBProject project, Object owner) in c:\Users\Mathieu\Source\Repos\Rubberduck\Rubberduck.Parsing\VBA\RubberduckParser.cs:line 81
   at Rubberduck.Inspections.Inspector.<>c__DisplayClass10.<Parse>b__f() in c:\Users\Mathieu\Source\Repos\Rubberduck\RetailCoder.VBE\Inspections\Inspector.cs:line 106
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Rubberduck.Inspections.Inspector.<Parse>d__12.MoveNext() in c:\Users\Mathieu\Source\Repos\Rubberduck\RetailCoder.VBE\Inspections\Inspector.cs:line 106
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Rubberduck.UI.CodeInspections.CodeInspectionsDockablePresenter.<RefreshAsync>d__12.MoveNext() in c:\Users\Mathieu\Source\Repos\Rubberduck\RetailCoder.VBE\UI\CodeInspections\CodeInspectionsDockablePresenter.cs:line 201
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Rubberduck.UI.CodeInspections.CodeInspectionsDockablePresenter.<Refresh>d__f.MoveNext() in c:\Users\Mathieu\Source\Repos\Rubberduck\RetailCoder.VBE\UI\CodeInspections\CodeInspectionsDockablePresenter.cs:line 178
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__0(Object state)

************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18063 built by: FX45RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
Rubberduck
    Assembly Version: 1.4.5657.42466
    Win32 Version: 1.4.0.0
    CodeBase: file:///C:/ProgramData/Rubberduck/Rubberduck.DLL
----------------------------------------
Microsoft.Vbe.Interop
    Assembly Version: 14.0.0.0
    Win32 Version: 14.0.4760.1000
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.Vbe.Interop/14.0.0.0__71e9bce111e9429c/Microsoft.Vbe.Interop.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18021 built by: FX45RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34238 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34251 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
Rubberduck.VBEditor
    Assembly Version: 1.0.5657.42461
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/ProgramData/Rubberduck/Rubberduck.VBEditor.DLL
----------------------------------------
Accessibility
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
Rubberduck.Parsing
    Assembly Version: 1.0.5657.42462
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/ProgramData/Rubberduck/Rubberduck.Parsing.DLL
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34234 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18060 built by: FX45RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
Microsoft.GeneratedCode
    Assembly Version: 1.0.0.0
    Win32 Version: 4.0.30319.34234 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
PresentationFramework
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18060
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.dll
----------------------------------------
WindowsBase
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18060 built by: FX45RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/WindowsBase/v4.0_4.0.0.0__31bf3856ad364e35/WindowsBase.dll
----------------------------------------
PresentationCore
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18060 built by: FX45RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/PresentationCore/v4.0_4.0.0.0__31bf3856ad364e35/PresentationCore.dll
----------------------------------------
System.Xaml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18015 built by: FX45RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xaml/v4.0_4.0.0.0__b77a5c561934e089/System.Xaml.dll
----------------------------------------
Rubberduck.SourceControl
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/ProgramData/Rubberduck/Rubberduck.SourceControl.DLL
----------------------------------------
NLog
    Assembly Version: 3.2.1.0
    Win32 Version: 3.2.1.0
    CodeBase: file:///C:/ProgramData/Rubberduck/NLog.DLL
----------------------------------------
office
    Assembly Version: 14.0.0.0
    Win32 Version: 14.0.4760.1000
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/office/14.0.0.0__71e9bce111e9429c/office.dll
----------------------------------------
CustomMarshalers
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/CustomMarshalers/v4.0_4.0.0.0__b03f5f7f11d50a3a/CustomMarshalers.dll
----------------------------------------
Antlr4.Runtime.net45
    Assembly Version: 4.3.0.0
    Win32 Version: 4.3.0.0
    CodeBase: file:///C:/ProgramData/Rubberduck/Antlr4.Runtime.net45.DLL
----------------------------------------
Microsoft.CSharp
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.CSharp/v4.0_4.0.0.0__b03f5f7f11d50a3a/Microsoft.CSharp.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

Once I close the NRE error window, I can click the CI refresh button, and it will parse with no error.

This happens when the Code Inspections window is the first RD window opened in the IDE. If I open Code Explorer first, then open CI, I don't get the error until I click the refresh button, then I'll get the NRE. I can then click refresh again, and it will properly parse.

retailcoder commented 9 years ago

This is a bug with the resolver, here's a quick repro:

Class1

Public Sub DoSomething()

    Dim c As New Class2
    Debug.Print c.Foo
    Debug.Print c!Foo 'not picked up as a reference (well that's a new one!)

    Dim x As New Application
    Debug.Print x.ActiveCell.Address
    Debug.Print x!ActiveCell.Address '"freezes" code explorer and crashes code inspections

End Sub

Class2

Public Property Get Foo() As String
End Property

Fix is in progress.

retailcoder commented 9 years ago

Turns out this:

Debug.Print c!Foo 'not picked up as a reference (well that's a new one!)

Is yet another bug in the grammar. the procedure call Debug.Print has an ArgContext, but that context only includes c!, where the ! is picked up as a type hint (which fires up a false positive with the type hint inspection).

I'm opening another issue.