False Positive (squid S1172) : Unused method parameters should be removed (Struts 1.x)

956 views
Skip to first unread message

Charles Morin

unread,
Nov 1, 2016, 1:58:05 PM11/1/16
to SonarQube
I'm facing a false positive when it comes to analyzing Apache Struts 1.x projects.

Here is a typical controller class method:

public ActionForward addUser(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {
...
}

Those parameters are required by Struts. Removing the unused parameters breaks the method.

SonarQube version: 5.5
Plugins installed:


Thank you

Charles
Auto Generated Inline Image 1

Scott B.

unread,
Nov 1, 2016, 2:08:55 PM11/1/16
to SonarQube
Hi.

https://sonarqube.com/coding_rules#rule_key=squid%3AS1172

"Exceptions

Override and implementation methods are excluded (...)"

Couldn't you add the @Override to these methods? SonarQube cannot guess if the method overrides another method or not.

Charles Morin

unread,
Nov 1, 2016, 3:11:02 PM11/1/16
to SonarQube
Unfortunately, adding @Override on that method does not makes sense in that context.

Doing so raises a compilation error:
"The method addUser(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse) of type UserEditAction must override or implement a supertype method"

A Struts 1.x action class extends Action, and there is no addUser method in Action, so I cannot override that.

Thank you.

Michael Gumowski

unread,
Nov 2, 2016, 4:38:29 AM11/2/16
to Charles Morin, SonarQube
Hello Charles,

If the method is not an override, is there any other way to identify the class containing it as being related to Struts? (extending a Struts class, implementing a Struts interface, annotated with something particular?)

Without being able to identify the method as following Struts constraints it will be hard to do something about it.

Cheers,

--
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/b237a032-beca-48f5-aa1f-5fa8d7b49a34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

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

Charles Morin

unread,
Nov 2, 2016, 8:04:17 AM11/2/16
to SonarQube, charl...@gmail.com
Yes, there is a way to identify that.

All Struts 1.x actions are in concrete inheritance against the framework.

Typical parent classes are:
  • Action
  • BaseAction
  • DispatchAction
  • DownloadAction
  • EventDispatchAction
  • ForwardAction
  • IncludeAction
  • LocaleAction
  • LookupDispatchAction
  • MappingDispatchAction
  • SwitchAction
See the source here:
Thank you

Charles

Michael Gumowski

unread,
Nov 3, 2016, 12:53:10 PM11/3/16
to Charles Morin, SonarQube
Hey Charles,

Thanks a lot for the precision. So basically, as soon as a class is a subclass from the Struts 1.x Action class, you may end with mandatory extra parameters. In such cases, they are indeed false positives.

I created the following ticket to handle the issue: https://jira.sonarsource.com/browse/SONARJAVA-1928

Cheers,


For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages