Following example shows CRR0027 on line 8 ("result = splitted(0).ToUpper") although NullReferenceException is never thrown:
Visual BasicPublic Module Module1
Function Foo(text As String) As String
Dim result As String = text
If text IsNot Nothing Then
Dim splitted As String() = text.Split({" "c}, StringComparison.Ordinal)
result = splitted(0).ToUpper
End If
Return result
End Function
'Examples:
' Foo("Hello World!") => "HELLO"
' Foo("Morning!") => "MORNING!"
' Foo("") => ""
' Foo(Nothing) => Nothing
End Module
Hi Robert,
Thank you for trying the Possible NullReference diagnostic beta feature. I have reproduced this false positive report. You will be notified when we prepare a fix.