False positive unused method parameter annotated with @Observes

80 views
Skip to first unread message

bobb...@gmail.com

unread,
Oct 1, 2015, 9:46:29 AM10/1/15
to SonarQube
In the following example the parameter annotated with @Observes is marked as an unused method parameter. In this case the parameter denotes which events are handled by the method so the parameter should not be removed as suggested by SonarQube.


public void onLoginFailed(@Observes LoginFailedEvent event, DefaultLoginCredentials loginCredentials) throws ServiceException {
 
//Some code that doesn't use event
}



Freddy Mallet

unread,
Oct 2, 2015, 5:01:42 AM10/2/15
to bobb...@gmail.com, SonarQube
@Java team, what's your feeling about this corner case ? I would adopt the same strategy that the one for unused private methods :https://jira.sonarsource.com/browse/SONARJAVA-1179. As soon as a parameter is annotated, let simply ignore this parameter. 

++


Freddy MALLET | SonarSource
Product Director & Co-Founder
http://sonarsource.com

--
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/d80b3803-8951-4ddd-9935-5aeb9320d845%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Gumowski

unread,
Oct 2, 2015, 5:20:40 AM10/2/15
to Freddy Mallet, bobb...@gmail.com, SonarQube
Hello bobbrinks, Freddy,

@bobbrinks, thank you for you feedback!
@Freddy, sounds like a good strategy!

The following ticket have been created to improve the rules behavior: https://jira.sonarsource.com/browse/SONARJAVA-1299

Regards,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

Sebastien Lesaint

unread,
Oct 5, 2015, 9:46:33 AM10/5/15
to Michael Gumowski, Freddy Mallet, bobb...@gmail.com, SonarQube
Freddy,

Would parameter be ignored for any annotation?

Ignoring the annotation when parameter is annotated with @Nonnull or @Nullable or other anotations of the kind does not seem appropriate to me.

Sébastien LESAINT | SonarSource
Platform Developer

Nicolas Peru

unread,
Oct 5, 2015, 9:55:55 AM10/5/15
to Sebastien Lesaint, Michael Gumowski, Freddy Mallet, bobb...@gmail.com, SonarQube
@Sebastien We postponed this discussion to ticket implementation time, see the comments in the ticket created by @Michael

Nicolas PERU | SonarSource
Senior Developer
http://sonarsource.com


Reply all
Reply to author
Forward
0 new messages