Skip to content

Commit c6e06e6

Browse files
committed
Correct null checks in VBComponent(s).
1 parent 19108fe commit c6e06e6

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Rubberduck.VBEEditor/SafeComWrappers/VBA/VBComponent.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ public string ExportAsSourceFile(string folder)
131131

132132
public IVBProject ParentProject
133133
{
134-
get
135-
{
136-
return Collection != null ? Collection.Parent : null;
137-
}
134+
get { return Collection.Parent; }
138135
}
139136

140137
private void ExportUserFormModule(string path)

Rubberduck.VBEEditor/SafeComWrappers/VBA/VBComponents.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ public IVBComponent this[object index]
4242

4343
public void Remove(IVBComponent item)
4444
{
45-
if (!IsWrappingNullReference) Target.Remove((VB.VBComponent)item.Target);
45+
if (item != null && item.Target != null && !IsWrappingNullReference)
46+
{
47+
Target.Remove((VB.VBComponent)item.Target);
48+
}
4649
}
4750

4851
public IVBComponent Add(ComponentType type)

RubberduckTests/Inspections/ProcedureNotUsedInspectionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ Private Sub abc_Foo(ByVal arg1 As Integer, ByVal arg2 As String)
196196
var inspection = new ProcedureNotUsedInspection(parser.State);
197197
var inspectionResults = inspection.GetInspectionResults();
198198

199-
Assert.AreEqual(1, inspectionResults.Count(result => result.Target.DeclarationType == DeclarationType.Procedure));
199+
Assert.AreEqual(0, inspectionResults.Count(result => result.Target.DeclarationType == DeclarationType.Procedure));
200200
}
201201

202202
[TestMethod]

0 commit comments

Comments
 (0)