Always true inspection - Is it a bug?

"expected != null" and "actual != null" are always true. They cannot.

This problem happens with Demetra build 5181 and 5201



Attachment(s):
AlwaysTrue.png
9 comments

I think you're wrong here and Demetra is right.

Take the first part of the second if:

(actual == null) && (expected != null)

If actual == null holds true, then expected can't be null, otherwise you
had already returned after the first if. Therefore expected != null is
always true there.

The same applies for the second part.

t800t8 wrote:

"expected != null" and "actual != null" are always true. They cannot.

This problem happens with Demetra build 5181 and 5201


------------------------------------------------------------------------


--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0

Yeah, I'm wrong. IDEA is winner ;)

0

But I found another problem. IDEA should be more intelligent, actual and expected can't be null.

Please check attached picture for more detail.



Attachment(s):
MoreIntelligent.png
0

Hello t800t8,

Is that fail() comes from JUnit? Otherwise we have no idea fail() will not
ever return. Just substitute fail() call with any other method call and you'll
see reason why IDEA complaints.

-


Maxim Shafirov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

But I found another problem. IDEA should be more intelligent. Please
check attached picture for more detail.



0

Maxim,

No, it's my own.


Agree with you, IDEA can't know about fail(). :)

Hello t800t8,

Is that fail() comes from JUnit? Otherwise we have no
idea fail() will not
ever return. Just substitute fail() call with any
other method call and you'll
see reason why IDEA complaints.

------------------
Maxim Shafirov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

But I found another problem. IDEA should be more

intelligent. Please

check attached picture for more detail.

>

0

I think it would be reasonable for IDEA to step into private methods in
this case. Or maybe we should adopt @NeverReturns annotation or something.

t800t8 wrote:

Maxim,

No, it's my own.

     private static void fail(String message) {
>         throw new AssertionError(message);
>     }
> ]]>


Agree with you, IDEA can't know about fail(). :)

>> Hello t800t8,
>>
>> Is that fail() comes from JUnit? Otherwise we have no
>> idea fail() will not
>> ever return. Just substitute fail() call with any
>> other method call and you'll
>> see reason why IDEA complaints.
>>
>> -


>> Maxim Shafirov
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>>
>>> But I found another problem. IDEA should be more
>> intelligent. Please
>>> check attached picture for more detail.
>>>
>>

0

Very easy explanation.

The function first returns if both actual and expected are null.
If it doesn't return due to the 1st if statement it means that either
expected or actual are not null.

In the 2nd if statement, if actual is null it implies that expected is
not null and vise versa.

That's why the 2nd if statement can be:
if (actual == null || expected == null).

Demetra is right.

Amnon

0

I guess I should have read the rest of the thread before I replied :(

Sorry

0

Please sign in to leave a comment.