Unused parameter false positive

680 megtekintés
Ugrás az első olvasatlan üzenetre

Michel Pawlak

olvasatlan,
2016. márc. 17. 7:54:522016. 03. 17.
– SonarQube
Hi, 

I don't know if this has already been discussed / reported / fxed, but we have false positives with the "unused parameter" rule. These false positives do occur when the body of the method does not use the parameter, but the method is annotated with a custom annotation. The parameter is in fact used by the interceptor.

The easy fix would be to avoid creating this type of issues when the method is annotated. The more complex one would be to detect the underlying interceptor and check if it tries to access the parameter that is suspected to be unused.

Michel

Michael Gumowski

olvasatlan,
2016. márc. 18. 13:11:512016. 03. 18.
– Michel Pawlak, SonarQube
Hey Michel,

The rule have been already discussed in this group was updated to ignore unused parameters annotated with 'javax.enterprise.event.Observes' (See SONARJAVA-1299 and this thread).
Unused parameters from methods which are overriding from a parent/class or implementing an interface are also ignored. 

During implementation of SONARJAVA-1299, we decided to use a white list approach, meaning that if parameters are annotated with other annotations covering similar cases, the rule can be extended. Could you think about a (not custom) annotation which could do the trick directly on the parameter?

About the approaches you propose, simply ignoring annotated methods is too drastic. Regarding analysis of the Interceptor, we are note quite ready to do such checking.

Cheers,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
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/c6218ed3-b0bd-4fab-9989-89d641dcab6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michel Pawlak

olvasatlan,
2016. márc. 22. 5:42:172016. 03. 22.
– SonarQube, michel...@gmail.com
Hi Michael,

Sorry for the late reply. I'm not sure I understand this part of your answer:


Could you think about a (not custom) annotation which could do the trick directly on the parameter? 

Are you thinking about annotating parameters detected as "unused" with @SuppressWarnings("unused")?

Michel

Michael Gumowski

olvasatlan,
2016. ápr. 11. 9:37:382016. 04. 11.
– Michel Pawlak, SonarQube
Hello Michel,

My turn to be late... sorry.
No, I was thinking about an annotation directly on the parameter, for instance with this fake annotation:

public void foo(@FlagParameter Boolean doStuff) {

For the moment, the rule notably ignores unused parameters annotated with @Observes, so I was wondering if a similar annotation could cover your usage. In such situation we would add it to the annotation to handle.

Regards,

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

Michel Pawlak

olvasatlan,
2016. ápr. 11. 11:27:132016. 04. 11.
– SonarQube, michel...@gmail.com
Hi Michael,

Unfortunately I can't think of a generic, non-custom, annotation we could use in such a context. I guess that we'll use an interface or write our own custom rule then.

Regards,

Michel

banchare...@gmail.com

olvasatlan,
2016. ápr. 27. 6:05:182016. 04. 27.
– SonarQube
Hi,
I have a similar false negative with GWT code using UiBinder :

@UiHandler({ "button" })
void onButtonClicked(ClickEvent event) {

Even if I don't use the "event" argument, I can't remove it.

Would it be possible to add this in the white list ?
Maybe something like : isEventHandler(MethodTree tree)

Thanks,
Fabien Bancharel.

banchare...@gmail.com

olvasatlan,
2016. ápr. 27. 7:07:072016. 04. 27.
– SonarQube
By false negative, I mean a reported violation, that should not be reported.

Michael Gumowski

olvasatlan,
2016. máj. 19. 9:31:042016. 05. 19.
– banchare...@gmail.com, SonarQube
Hello Fabien,

Thank you for your feedback, and sorry for the late reply.

Based on the previous feedback from Michel, the best and simplest option is then to ignore annotated methods. Handling every specific case, like yours, would be too costly for us. 

As a side note, you observed a False Positive [FP], which means that the analyzer reported an issue, when none was expected. A False Negative [FN] is the opposite: the analyzer reported nothing, despite the fact that there was an issue in the code which should have been raised.

Cheers,


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

On 27 April 2016 at 13:07, <banchare...@gmail.com> wrote:
By false negative, I mean a reported violation, that should not be reported.

--
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.
Válasz mindenkinek
Válasz a szerzőnek
Továbbítás
0 új üzenet