Code analysis bug in 4.0.738.4?
In the following method Resharper (4.0.738.4) says that the expression (item != null) would be always true and can be removed. I disagree.
*private static int CountNotNullItems()
{
string[] items = { "1", null, "2" };
int i = 0;
foreach (string item in items)
{
if (item != null)
{
i++;
}
}
return i;
}*
Please sign in to leave a comment.
Thank you for the report. This issue will be fixed shortly
--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Tomas Elison" <no_reply@jetbrains.com> wrote in message
news:27535671.1204636272559.JavaMail.itn@is.intellij.net...
>
>
Hello,
I ran into a similar error. The 'if' statement here is falsely flagged as being always true. I believe this is a mistake since the ResolveUri method can return null, according to the .Net documentation.
public static string GetResourcePath(Uri resourceUri)
{
string path = null;
string localPath = resourceUri.LocalPath;
Uri uri = DefaultXmlResolver.ResolveUri(null, localPath);
if (uri != null)
path = uri.LocalPath;
return path;
}
My info:
Build 5.1.1766.4 on 2011-01-12T16:31:10
Visual Studio 10.0.30319.1.
--Ron
edit:
DefaultXmlResolver is a property of ours that returns a type that derives from System.Xml.XmlUrlResolver, but we don't override ResolveUri(). The following replacement line also generates the false "expression is always true" notice on the 'if' statement:
Uri uri = (new XmlUrlResolver()).ResolveUri(null, localPath);