Unused parameter false positive

瀏覽次數:676 次
跳到第一則未讀訊息

Michel Pawlak

未讀,
2016年3月17日 清晨7:54:522016/3/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

未讀,
2016年3月18日 下午1:11:512016/3/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

未讀,
2016年3月22日 清晨5:42:172016/3/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

未讀,
2016年4月11日 上午9:37:382016/4/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

未讀,
2016年4月11日 上午11:27:132016/4/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

未讀,
2016年4月27日 清晨6:05:182016/4/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

未讀,
2016年4月27日 清晨7:07:072016/4/27
收件者:SonarQube
By false negative, I mean a reported violation, that should not be reported.

Michael Gumowski

未讀,
2016年5月19日 上午9:31:042016/5/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.
回覆所有人
回覆作者
轉寄
0 則新訊息