Why am I receiving 'Condition strSource == null is always true' to remove this and others when I know it is wrong?

Answered

I'm a newbee using Intellij in this case, and the 'ReSharper' as I've learned generates this warning, but this warning seems incorrect to me: "Condition 'strSource == null' is always true". I've done some reading on this support site and StackOverflow and can accept I just may be too thick to understand. However, my unit testing this proves otherwise. Could someone help me understand this? The warning arises with these two bits of code in the context of the code below. 

Sample A: I know in unit testing 'code sample A', that strTopic would in fact return "null" or "" and produce such a scenario. I couldn't simply use one argument for both cases like I can in other languages by simply adding ".trim()." If I did so, it would error on a  "null" value. So this is one reason why I'm confused. 


Sample B: Again, in unit testing 'code sample B', strSource == null can in fact happen. 

I can accept being wrong, just help me understand.

Code Sample A:
(strTopic == null || strTopic.contentEquals(""))

Code Sample B:
(strSource == null)

Within Context:

1
2
3
4
5
6
7
       if(strSource != null && strTopic != null){
           rslt = true;
       }else if (strSource != null && (strTopic == null || strTopic.contentEquals(""))){
           msg = "Please select or enter a topic.";
       }else{
           if((strSource == null) && (strTitle.isEmpty())){
               msg = "Please enter a title for the source.";
 
... embedded 'if's continue...
0
1 comment

Could you please share the complete code and specify the lines where the inspection is not correct? Please use GitHub or upload at https://intellij-support.jetbrains.com/hc/articles/206869619.

0

Please sign in to leave a comment.