1 Replies Last post: Feb 4, 2010 9:30 PM by Mike Strobel  
Guest
Currently Being Moderated

Feb 4, 2010 9:26 PM

False Positive w/ Pessimistic Value Analysis

When switching value analysis mode to "pessimistic" (Build 1609), I get a

false warning with the following code:

 

internal sealed class IndexedEnumerableDebugView collection)

    {

        if (collection == null)

            throw new ArgumentNullException("collection");

        _collection = collection;

    }

 

    DebuggerBrowsable(DebuggerBrowsableState.RootHidden)

    public T[] Items

    {

        get

        {

            var items = new T[_collection.Count];

            // On the following line, R# incorrectly warns "_collection" may

be null.

            _collection.CopyTo(items, 0);

            return items;

        }

    }

}

 

Since "_collection" is a private readonly field in a sealed class, and

"Items" is not accessed before the field is assigned, the field cannot

possibly be null.  Further, a NullReferenceException would have already been

thrown by the previous statement when accessing "_collection.Count".

 

 

More Like This

  • Retrieving data ...