Wrong inspection result of "Property doesn't return a value on all code paths"?

In the code i maintain i found following property declaration:

Friend ReadOnly Property LieferantenIDs() As Integer()
          Get
 
               mviIDLieferantenLauf.CopyTo(LieferantenIDs, 0)
 
          End Get
     End Property

R# warns "Property LieferantenIDs doesn't return a value on all code paths" but the code works fine. Is this a bug in code analysis or do i miss something?

Environment: Visual Studio 2010 SP1 with R# 7.0 build 79.

Regards
Klaus
2 comments
Comment actions Permalink

Hello Klaus
     I've tried the following console application:

    Module Module1

    Sub Main()
        Dim c As C = New C()
        Console.WriteLine(c.LieferantenIDs.Length)
    End Sub

    End Module

     Class C
         Private mviIDLieferantenLauf As Integer() = New Integer() {1, 2, 3}

         Friend ReadOnly Property LieferantenIDs() As Integer()
             Get

->                 mviIDLieferantenLauf.CopyTo(LieferantenIDs, 0)

             End Get
     End Property
     End Class

and it failes with ArgumentException: Value cannot be null on the indicated line. Let me know if this helps. Thank you!

Andrey Serebryansky

Senior Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

0
Comment actions Permalink

Hello Andrey,

sorry that i just looked at the sourcecode and the R# warning and don't tested it. A deeper look at the code shows me that the property wasn't used. And there is a similar construct at another place in the code where the CopyTo(...) is preceeded by a ReDIm statement. So it's definetly a coding error.

But the text of the R# warning is a bit misleading here because it's also used if i have "if .. else" or "switch" statements in a function and no final return statement. I would expect a message like "Possible null reference" here.

Regards
Klaus

0

Please sign in to leave a comment.