-
Notifications
You must be signed in to change notification settings - Fork 151
Pre and Post Conditions are suggested for "value != null" even when there is already a condition for !string.IsNullOrWhiteSpace(value) #437
Comments
Thanks a lot. Could you provide a version of Code Contract that you're using? |
I've tried with |
I am using the latest RC - DotNet.Contracts 1.10.20606.1 Yes. I also get the same issue with string.IsNullOrEmpy() |
What version of .NET Framework are you targetting? This smells like #339 to me. |
.Net Framework is 4.5.1.1 |
How did you get a .NET 4.5.1.1 target framework? As far as I know, that doesn't exist. |
I can reproduce this using String.IsNullOrEmpty as follows: public class Test
{
private readonly string m_name;
public Test(string name)
: base()
{
Contract.Requires(!string.IsNullOrEmpty(name));
m_name = name;
}
public string Name
{
get
{
Contract.Ensures(!string.IsNullOrEmpty(Contract.Result<string>()));
// warning : CodeContracts: Consider adding the postcondition
// Contract.Ensures(Contract.Result<System.String>() != null); to provide extra-
// documentation to the library clients
return m_name;
}
}
[ContractInvariantMethod]
private void ObjectInvariant() => Contract.Invariant(!string.IsNullOrEmpty(m_name));
} I'm not sure this is related to #339 since there is no mention of [Pure] in the warning. This was tested with VS 2015 Update 2 and Code Contracts 1.9.10714.2. The warning occurs for me when targeting both 4.6 and 4.6.1. |
It seems that cccheck can't infer relationship between nullness of the variable from the predicate Valid bug and it seems that this is not a regression. We'll see what we can do. Up for grabs:) |
Was using .NET Fx 4.5.1 Thanks for confirming the issue Sergey. |
While this doesn't create incorrect behavior, it does create a lot of noise and make the true warnings much less valuable.
The text was updated successfully, but these errors were encountered: