TextAreaAutomationPeer throws NullReferenceException at some cases #194

Open
opened 2019-09-10 00:18:13 -05:00 by sloutsky · 0 comments
sloutsky commented 2019-09-10 00:18:13 -05:00 (Migrated from github.com)

https://github.com/icsharpcode/AvalonEdit/blob/master/ICSharpCode.AvalonEdit/Editing/TextAreaAutomationPeer.cs: line 118

FromElement(editor) may return null in some (random) cases - and the current code throws NullReferenceException.
The suggestion (below) is to check returned value and fall-back to 'retrun base.GetPattern(patternInterface)'

        public override object GetPattern(PatternInterface patternInterface)
	{
		if (patternInterface == PatternInterface.Text)
			return this;
		if (patternInterface == PatternInterface.Value)
			return this;
		if (patternInterface == PatternInterface.Scroll) {
			TextEditor editor = TextArea.GetService(typeof(TextEditor)) as TextEditor;
			if (editor != null)
			{
				var fromElement = FromElement(editor);
				if (fromElement != null)
					fromElement.GetPattern(patternInterface);
			}
		}
		return base.GetPattern(patternInterface);
	}
https://github.com/icsharpcode/AvalonEdit/blob/master/ICSharpCode.AvalonEdit/Editing/TextAreaAutomationPeer.cs: line 118 FromElement(editor) may return null in some (random) cases - and the current code throws NullReferenceException. The suggestion (below) is to check returned value and fall-back to 'retrun base.GetPattern(patternInterface)' public override object GetPattern(PatternInterface patternInterface) { if (patternInterface == PatternInterface.Text) return this; if (patternInterface == PatternInterface.Value) return this; if (patternInterface == PatternInterface.Scroll) { TextEditor editor = TextArea.GetService(typeof(TextEditor)) as TextEditor; if (editor != null) { var fromElement = FromElement(editor); if (fromElement != null) fromElement.GetPattern(patternInterface); } } return base.GetPattern(patternInterface); }
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-icsharpcode/AvalonEdit#194
No description provided.