Incorrect: Expression is always false

In R# build 804 I have a DbConnection implementation which this code:


on "value == null" it says "Expression is always false". I don't understand why R# says this. It's a public property. Surely someone can try to assign null to it, that's why the check is there. I tried to create a small reproducible but did not get the error on a mostly empty DbConnection implementation.

The project is open source, System.Data.SQLite from http://sqlite.phxsoftware.com/

the class declaration is


This is in Visual Studio 2005. I was not able to reproduce the error in a mostly empty DbConnection implementation--I supposed something else within SQLiteConnection is triggering this problem.


Thanks,

Sam

3 comments
Comment actions Permalink

The overriden property is marked by attribute.
This warning is fixed in the bugfix update.

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Samuel Neff" <no_reply@jetbrains.com> wrote in message
news:25316126.63651212606399037.JavaMail.jive@app4.labs.intellij.net...

In R# build 804 I have a DbConnection implementation which this code:

>

    public override string ConnectionString
>    {
>      get
>      {
>        return _connectionString;
>      }
>      set
>      {
>        if (value == null)
>          throw new ArgumentNullException();
>
>        else if (_connectionState != ConnectionState.Closed)
>          throw new InvalidOperationException();
>
>        _connectionString = value;
>      }
>    }
> ]]>

>

on "value == null" it says "Expression is always false". I don't
understand why R# says this. It's a public property. Surely someone can
try to assign null to it, that's why the check is there. I tried to
create a small reproducible but did not get the error on a mostly empty
DbConnection implementation.

>

The project is open source, System.Data.SQLite from
http://sqlite.phxsoftware.com/

>

the class declaration is

>

 public sealed partial class SQLiteConnection : DbConnection, ICloneable
> ]]>

>

This is in Visual Studio 2005. I was not able to reproduce the error in a
mostly empty DbConnection implementation--I supposed something else within
SQLiteConnection is triggering this problem.

>
>

Thanks,

>

Sam



0
Comment actions Permalink

Thanks. I'm a little confused though, even with a NotNull attribute, doesn't that mean that the getter will never return null but within the setter, "value" can still be null? I'm not sure if this was fixed by removing the NotNull attribute or if what I'm describing here is actually what is being fixed.

Best regards,

Sam

0
Comment actions Permalink

When the property is marked by attribute, it is supposed the it
won't return null from getter and won't receive null in setter. So, the
analysis of code which use this property can rely on this.

Definitely, there should be some consistency checks. For example
if (value == null) thow new ArgumentNullException(...);

I've fixed the detection of such consistency checks


--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Samuel Neff" <no_reply@jetbrains.com> wrote in message
news:7519585.65651212677795757.JavaMail.jive@app4.labs.intellij.net...

Thanks. I'm a little confused though, even with a NotNull attribute,
doesn't that mean that the getter will never return null but within the
setter, "value" can still be null? I'm not sure if this was fixed by
removing the NotNull attribute or if what I'm describing here is actually
what is being fixed.

>

Best regards,

>

Sam



0

Please sign in to leave a comment.