Menu

#1405 UnusedPrivateMethod false positive?

PMD-5.3.4
closed
None
PMD
3-Major
Bug
UnusePrivateMethod
2015-09-17
2015-09-16
No

Hi,

I have a problem with the following Code.

PMD5.3.3 think that the method "getImageUrlsListForVariant" is unused, but it is used as you can see.

Whats wrong with the rule?

public class blabla implements blabla2 {

    @Override
    public List<String> getProductImageUrls(final ApparelStyleVariantProductModel product, final String format) {
        return getImageUrlsListForVariant(product, format);
    }

    private List<String> getImageUrlsListForVariant(final VariantProductModel variant, final String format) {
        final SortedMap<Integer, String> imageUrls = getImageUrlsMapForVariant(variant, format); 
        return new ArrayList<String>(imageUrls.values());
  }
}

Thanks
Mark

Discussion

  • Patrick McEvoy

    Patrick McEvoy - 2015-09-16

    Similar to 1279.

     
  • Andreas Dangel

    Andreas Dangel - 2015-09-16

    Hi,
    thanks for the report.

    How do you execute PMD? For this situation, it is important to know about the "auxClasspath" option. It seems, that you run PMD with this option turned on.
    The effect of this option is, that PMD will use the the runtime classpath of your application during analysis of your source code, so that less false negatives are produced. However, if you run PMD with this option provided, but the classpath doesn't contain the necessary classes, then, it will produce false positives, like in your case. I assume, that ApparelStyleVariantProductModel is a subclass of VariantProductModel - but PMD doesn't know about this.

    If you use PMD via the maven plugin, make sure, you run it after the compile phase, so that your own classes are on the classpath, too.

    Thanks,
    Andreas

     
  • Andreas Dangel

    Andreas Dangel - 2015-09-16
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -6,7 +6,7 @@
    
     Whats wrong with the rule?
    
    --------------------------------------
    +~~~~~
     public class blabla implements blabla2 {
    
         @Override
    @@ -19,7 +19,7 @@
             return new ArrayList<String>(imageUrls.values());
       }
     }
    -
    +~~~~~
    
     Thanks
     Mark
    
    • status: open --> more-info-needed
    • assigned_to: Andreas Dangel
    • Milestone: PMD-5.3.3 --> PMD-5.3.4
     
  • Mark Lübbehüsen

    Hi Andreas ,

    thanks for your reply.

    I dont use auxclasspath as you can see below. I am using ANT and JAVA 8

    <taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask">
    <classpath>
    <fileset dir="${build.common.bin.dir}/pmd/lib" includes="*.jar"/>
    </classpath>
    </taskdef>

    <target name="pmd" description="Performs PMD checks">
        <setPMDJavaVersion />
        <echo message="PMD Java Version: ${pmd.java.version}" />
        <mkdir dir="${report.dir}/pmd" />
        <pmd rulesetfiles="${pmd.ruleset.file}" shortFilenames="false" failonruleviolation="false">
            <sourceLanguage name="java" version="${pmd.java.version}"/>
            <formatter type="xml" toFile="${report.dir}/pmd/pmd-report.xml" />
            <fileset refid="src.files" />
        </pmd>
    </target>
    
    I have no idea
    
    thanks,
    Mark
    
     
  • Andreas Dangel

    Andreas Dangel - 2015-09-17
    • status: more-info-needed --> closed
     
  • Andreas Dangel

    Andreas Dangel - 2015-09-17

    I could reproduce it now - it is indeed a ant problem. The PMDTask always sets up the auxclasspath, regardless whether it has been configured or not.

    This will be fixed with PMD 5.3.4.

    Commit: https://github.com/pmd/pmd/commit/e1a41bdf984fdd8f79d6f3638e339d9a7bb57194

     

Log in to post a comment.