UnusedPrivateMethod returns false positives
A source code analyzer
Brought to you by:
adangel,
juansotuyo
UnusedPrivateMethod returns false positives. It doesn't appear to matter if the method call is nested several times or not
First Example
public ModelAndView viewEntry(Model model, HttpServletRequest request) { //call private method. Flagged Method return view(model, VIEW); } /** THIS IS FLAGGED AS UNUSED **/ private ModelAndView view(Model model, String view) { //add values to the model //return the correct view return new ModelAndView(view, MVC_CONSTANTS.MODEL_KEY, model.asMap()); }
Second Example
public ModelAndView showLineGraph(HttpServletRequest request, HttpServletResponse response) throws ServletException { //call private method USAGE #1. Method not flagged MyObject filter = getGraphInnateFilter(request); //LINE GRAPHIC LOGIC //write output to response stream and return } public ModelAndView showPieChart(HttpServletRequest request, HttpServletResponse response) throws ServletException { //call private method USAGE #2. Method not flagg MyObject filter = getGraphInnateFilter(request); //PIE CHART LOGIC //write output to response stream and return } /** This method is NOT flagged as unused **/ private MyObject getGraphInnateFilter(HttpServletRequest request) { MyObject filter = new MyObject(); //call private method. Flagged method setInnateFilterFields(filter, request); //perfrom logic //return return filter; } /** THIS IS FLAGGED AS UNUSED **/ private void setInnateFilterFields(MyObject filter, HttpServletRequest request) { //add values to filter object }
Hi,
I unfortunately can't reproduce your two examples.
Could you please verify, that I created the correct test case for it?
These are the test cases I added: https://github.com/pmd/pmd/commit/c730c15d13568f9901492c3f54c4740c9b25b44e
Thanks,
Andreas
Hi Andreas,
Sorry about my delayed response, I have been out of town. Yes, you have the correct test case setup.
I have some time today and I'm going to play around with that class and see if I can find anything that triggers this bug specifically.
Thanks
MIchael
From: Andreas Dangel [mailto:adangel@users.sf.net]
Sent: Saturday, July 26, 2014 4:40 AM
To: [pmd:bugs]
Subject: [pmd:bugs] #1228 UnusedPrivateMethod returns false positives
Hi,
I unfortunately can't reproduce your two examples.
Could you please verify, that I created the correct test case for it?
These are the test cases I added: https://github.com/pmd/pmd/commit/c730c15d13568f9901492c3f54c4740c9b25b44e
Thanks,
Andreas
[bugs:#1228]http://sourceforge.net/p/pmd/bugs/1228 UnusedPrivateMethod returns false positives
Status: more-info-needed
Milestone: PMD-next
Created: Mon Jul 21, 2014 12:03 PM UTC by michael beaumont
Last Updated: Thu Jul 24, 2014 01:37 PM UTC
Owner: Andreas Dangel
UnusedPrivateMethod returns false positives. It doesn't appear to matter if the method call is nested several times or not
First Example
public ModelAndView viewEntry(Model model, HttpServletRequest request) {
}
/ THIS IS FLAGGED AS UNUSED /
private ModelAndView view(Model model, String view) {
}
Second Example
public ModelAndView showLineGraph(HttpServletRequest request, HttpServletResponse response) throws ServletException {
}
public ModelAndView showPieChart(HttpServletRequest request, HttpServletResponse response) throws ServletException {
}
/ This method is NOT flagged as unused /
private MyObject getGraphInnateFilter(HttpServletRequest request) {
}
/ THIS IS FLAGGED AS UNUSED /
private void setInnateFilterFields(MyObject filter, HttpServletRequest request) {
}
Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/pmd/bugs/1228/https://sourceforge.net/p/pmd/bugs/1228
To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/https://sourceforge.net/auth/subscriptions
This electronic message transmission and any attachments that accompany it contain information from DRC(r) (Dynamics Research Corporation) or its subsidiaries, or the intended recipient, which is privileged, proprietary, business confidential, or otherwise protected from disclosure and is the exclusive property of DRC and/or the intended recipient. The information in this email is solely intended for the use of the individual or entity that is the intended recipient. If you are not the intended recipient, any use, dissemination, distribution, retention, or copying of this communication, attachments, or substance is prohibited. If you have received this electronic transmission in error, please immediately reply to the author via email that you received the message by mistake and also promptly and permanently delete this message and all copies of this email and any attachments. We thank you for your assistance and apologize for any inconvenience.
Related
Issues:
#1228I have a similar problem, and noticed that as soon as I flip the location of methods in source the issue goes away.
For example the below source code flags as unused, but as soon as the view method is placed above the viewEntry method the violation goes away.
Hi James, I could reproduce your problem - thank you for your example. It's not about source location of the methods (at least not anymore) - it's about the @RequestParam annotation of the method parameter. This will be fixed with 5.1.3.
However, I still can't reproduce the original problem.
Thanks, Andreas
I am facing same or similar issue only on
PMD 5.1.2
:I have simplified my test case and found something that appears to be triggering this bug. The difference in my below code is that the method goes from having parameters, to none at all.
The below code does not flag for UnusedPrivateMethod
The below code DOES flag for UnusedPrivateMethod
Alright, the missing piece was the type resolution. I've added this, so that the
rule can actually detect subclasses. E.g. that DashboardGraphInnateFilter_o is
a subclass of DashboardInnateFilter_o. The same was the problem with
JTextField/JComponent.
You'll need to use the "-auxclasspath" command line option to set the class path,
so that the type resolution will work.
Can you please try this with the snapshot version and let me know, whether
it works?
https://sourceforge.net/projects/pmd/files/pmd/5.1.3-SNAPSHOT/
I'm sorry for this late reply.
I tried to use
pmd-bin-5.1.3-SNAPSHOT.zip
but I couldn't findlib/pmd-5.1.3.jar
in the zip file.Sorry, that's my fault.
I re-created the zip file, now lib/pmd-5.1.3-SNAPSHOT.jar is contained in the zip.
Thank you for the quick response.
I could download the new version, and the UnusedPrivateMethod false positives issues in my project has been substantially modified by the
PMD 5.1.3-SNAPSHOT
.This example will show the remaining issues:
I am running into this too... Is the status still "More Info Needed" because I think the issue is related to sub-classes AND type coercion. In one of my false-positive cases, I have a function that accepts primitive doubles, and I'm passing things like Double, double, and Float.
I'll close this ticket now. I believe, I have fixed all outstanding issues that have been mentioned in this thread, including inheritance, auto-boxing and double/float cases.
If this is not the case, please open a new ticket with a code sample.