rspec/rules/S4586/vbnet/rule.adoc

18 lines
530 B
Plaintext
Raw Normal View History

2020-06-30 12:49:37 +02:00
Returning <code>Nothing</code> from a non-<code>async</code> <code>Task</code>/<code>Task(Of T)</code> method will cause a <code>NullReferenceException</code> at runtime. This problem can be avoided by returning <code>Task.FromResult(Of T)(Nothing)</code> instead.
== Noncompliant Code Example
----
Public Function GetFooAsync() As Task(Of Object)
Return Nothing
End Function
----
== Compliant Solution
----
Public Function GetFooAsync() As Task(Of Object)
Return Task.FromResult(Of Object)(Nothing)
End Function
----