Method Signature Issues ignored if there us any @SuppressWarnings, even if its unrelated

59 views
Skip to first unread message

steve...@trustpayglobal.com

unread,
Jul 6, 2017, 6:34:40 AM7/6/17
to SonarLint
Hi,

I think there maybe an issue with reporting issues with unused method parameters using SonarLint in intellij (version 3.0.0.2041, Connected Mode) whereby if there is a SuppressWarning annotation on the method, the issues for squid:S1172 is removed.  Here is an example:

   @SuppressWarnings("unchecked")
   public static <T> T getAndRemoveAttribute(HttpSession session, String name, Class<T> cls) {
      if (session != null) {
         T value = (T) session.getAttribute(name);
         session.removeAttribute(name);
         return value;
      }
      return null;
   }
 

In this method, the parameter cls is reported correctly as unused, but if I change the annotation to anything else, e.g. @SuppressWarnings("222") then the warning goes away.  If my understand is correct then there may be other issues that are masked by the presence of any suppressed warnings.  

Hope this makes sense.

Regards

Steve

Michael Gumowski

unread,
Jul 11, 2017, 4:27:44 AM7/11/17
to steve...@trustpayglobal.com, SonarLint
Hello Steve,

Thanks for the feedback. What you are observing is a consequence of past work on these two tickets: SONARJAVA-1691SONARJAVA-1770

To sum things up, in order to not raise any false positives (FPs), and because we always prefer not to raise issue in case of doubt (false negative) rather than FPs, we usually ignore methods which are annotated, whatever the annotation may be.

There is however two cases where we currently ignore the annotation: when the method is annotated with @SuppressWarnings("unchecked") or @SuppressWarnings("rawtypes").

In your example, because the method is annotated with "unchecked", we ignore the annotation and consider the parameter as being unused. With the second case, as soon as you modify the annotation parameter, we fall back to the "annotated method" behavior, and therefore ignore the unused parameter.

We updated the rule description in order to be a lot more accurate regarding how it behaves. Next version of SonarJava plugin will include the new description, but you can already have a first look here: RSPEC-1805

Cheers,
Michael

Trustpay Global Limited is an authorised Electronic Money Institution regulated by the Financial Conduct Authority registration number 900043. Company No 07427913 Registered in England and Wales with registered address 130 Wood Street, London, EC2V 6DL, United Kingdom.

For further details please visit our website at www.trustpayglobal.com.

The information in this email and any attachments are confidential and remain the property of Trustpay Global Ltd unless agreed by contract. It is intended solely for the person to whom or the entity to which it is addressed. If you are not the intended recipient you may not use, disclose, copy, distribute, print or rely on the content of this email or its attachments. If this email has been received by you in error please advise the sender and delete the email from your system. Trustpay Global Ltd does not accept any liability for any personal view expressed in this message.

--
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/964a2a57-8831-40cd-8941-5ff18bb002e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Michael Gumowski | SonarSource
Software Developer, Language Team
http://sonarsource.com
Reply all
Reply to author
Forward
0 new messages