[JAVA] S2175 Inappropriate "Collection" calls should not be made - False Positive - A "Collection<AbstractItemModel>" cannot contain a "T"

342 views
Skip to first unread message

Adam Gabryś

unread,
Jul 3, 2017, 9:37:05 AM7/3/17
to SonarQube

Hello,

Java Plugin reported a False Positive for code:



This filter lambda should include all AbstractItemModel elements which are not contained by result collection. We cannot guarantee that result contains only instances of AbstractItemModel so we cannot use: ((Collection<AbstractItemModel>) value).stream().filter(element -> !result.contains(element))  (← this code is not marked as an error).


Environment:

  • SonarQube 5.6.6
  • SonarJava 4.9.0.9858


Best Regards,
Adam Gabryś

Michael Gumowski

unread,
Jul 10, 2017, 5:04:42 AM7/10/17
to Adam Gabryś, SonarQube
Hello Adam, 

Thanks a lot for the feedback and the first class reproducer that you provided. It's easing a lot investigation and it is really appreciated!

The root cause of the issue is hidden in our semantic engine, which resolve badly the lambda's type,  used in the filter(...) method. 

I created the following ticket to handle the issue, with a reduced case, extracted from your reproducer: SONARJAVA-2378

Cheers,
Michael


--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/VI1PR0801MB134162D15FBC11272431470C98D60%40VI1PR0801MB1341.eurprd08.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.
--
Michael Gumowski | SonarSource
Software Developer, Language Team
http://sonarsource.com
s2175.png
s2175.png
Reply all
Reply to author
Forward
0 new messages