Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 6c46af6

Browse files
committed
Fix NullReferenceException in SharpDevelopInsightWindow
1 parent 3b6892c commit 6c46af6

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeCompletionEditorAdapter.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ public override IInsightWindow ShowInsightWindow(IEnumerable<IInsightItem> items
7878
}
7979

8080
public override IInsightWindow ActiveInsightWindow {
81-
get { return textEditor.ActiveInsightWindow.activeAdapter; }
81+
get {
82+
if (textEditor.ActiveInsightWindow != null)
83+
return textEditor.ActiveInsightWindow.activeAdapter;
84+
else
85+
return null;
86+
}
8287
}
8388

8489
public override ICompletionListWindow ActiveCompletionWindow {

src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopInsightWindow.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,24 @@ protected override void DetachEvents()
9494

9595
void OnClosed(object sender, EventArgs e)
9696
{
97-
activeAdapter.OnClosed();
97+
if (activeAdapter != null)
98+
activeAdapter.OnClosed();
9899
}
99100

100101
void caret_PositionChanged(object sender, EventArgs e)
101102
{
102-
activeAdapter.OnCaretPositionChanged(e);
103+
// It is possible that the insight window is not initialized correctly
104+
// due to an exception, and then caret_PositionChanged is called in a finally block
105+
// during exception handling.
106+
// Check for a null adapter to avoid a NullReferenceException that hides the first exception.
107+
if (activeAdapter != null)
108+
activeAdapter.OnCaretPositionChanged(e);
103109
}
104110

105111
void document_Changed(object sender, DocumentChangeEventArgs e)
106112
{
107-
activeAdapter.OnDocumentChanged(e);
113+
if (activeAdapter != null)
114+
activeAdapter.OnDocumentChanged(e);
108115
}
109116
}
110117

0 commit comments

Comments
 (0)