Boolean expressions should not be gratuitous (squid:S2589)

497 views
Skip to first unread message

j...@qsm.co.il

unread,
Jan 11, 2018, 3:10:48 AM1/11/18
to SonarLint
The following code caused the above warning, which I believe to be incorrect, with the message "Remove this expression which always evaluates to "true"".

final Attachment ca = selKey.attachment();
               
if ((ca != null) && ca.isReading()) {
     
...
}

The JavaDoc for SelectionKey.attachment() says:
Returns: The object currently attached to this key, or null if there is no attachment

So null is indeed possible and the boolean it not necessarily true.


Nicolas Peru

unread,
Feb 2, 2018, 4:29:42 AM2/2/18
to j...@qsm.co.il, SonarLint
Hi, 

You did not specify which version of SonarLint you are using nor if it is in connected mode or not. 
I tried to reproduce the issue with your snippet but actually : https://docs.oracle.com/javase/8/docs/api/index.html?java/nio/channels/SelectionKey.html is returning Object so I am not sure your snippet is fully complete and accurate. 
In the end I could not reproduce the issue, can you please upgrade to latest version of SonarLint and latest version of SonarJava if you are using connected mode (5.1 at time of writing) and let us know if the issue persists.

Thanks.

--
You received this message because you are subscribed to the Google Groups "SonarLint" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarlint/15fa3e1a-2b3e-44cd-8691-68a939c3a4be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Nicolas Peru | SonarSource
Message has been deleted

j...@qsm.co.il

unread,
Feb 2, 2018, 4:51:08 AM2/2/18
to SonarLint
Dear Nicolas,

If this is any help, I was using the latest version of SonarLint for Eclipse. 

Jonathan

j...@qsm.co.il

unread,
Feb 2, 2018, 12:00:12 PM2/2/18
to SonarLint
Dear Nicolas,

I tested it again just now, after SonarLint was updated a few days ago, and the problem is no longer.

Jonathan
Reply all
Reply to author
Forward
0 new messages