Current filter:
                                You should refresh the page.
                                  • Please see following example, where "FooDict" contains the false positive (KeyValuePair is a structure). Compared with "FooList" the null-check is done with a class.

                                    [VB.NET]
                                    Public Class Class1 Private _dict As New Dictionary(Of Integer, String) Public Function FooDict() As Integer Dim result As Integer If _dict IsNot Nothing Then For Each item As KeyValuePair(Of Integer, String) In _dict If item.Value IsNot Nothing Then 'CRR0027 result += item.Value.Length End If Next End If Return result End Function Public Function BarDict() As Integer Dim result As Integer If _dict IsNot Nothing Then For Each item As KeyValuePair(Of Integer, String) In _dict Dim value As String = item.Value If value IsNot Nothing Then 'No CRR0027 result += value.Length End If Next End If Return result End Function '################################################################# Private Class Class2 Property Value As String End Class Private _list As New List(Of Class2) Public Function FooList() As Integer Dim result As Integer If _list IsNot Nothing Then For Each item As Class2 In _list If item?.Value IsNot Nothing Then 'No CRR0027 result += item.Value.Length End If Next End If Return result End Function End Class
                                • Dmitry O (DevExpress) 01.16.2018

                                  Hi Robert,

                                  Thanks for pointing out the problem. I have reproduced it with the help your code, I agree the "Possible System.NullReferenceException" issue should not be produced for your code
                                  "result += item.Value.Length", because "item" variable has structure type. We will try to fix the problem as soon as possible. Once we resolve it, we will let you know about this in the context of this ticket.

                                1 Solution

                                Creation Date Importance Sort by

                                Fixed: