Menu

#1292 False negative on "Avoid unused private methods"

New Tickets
more-info-needed
None
PMD
3-Major
Bug
5.2.2
2016-06-25
2014-12-05
mingoto
No

I get the "Avoid unused private methods" error on the two following code pieces:

(1)

@ContextConfiguration(classes = CucumberConfig.class)
public final class FlightSearchStepDefs {

  private FlightSearchPage flightSearchPage;
  private FlightResultPage flightResultPage;

  @Then("^I see resultpage banners for positions \"([^\"]*)\"$")
  public void I_see_resultpage_banners_for_positions(String bannerPositions) {
    checkBannerPositions(bannerPositions, flightResultPage);
  }

  @Then("^I see searchpage banners for positions \"([^\"]*)\"$")
  public void I_see_searchpage_banners_for_positions(String bannerPositions) {
    checkBannerPositions(bannerPositions, flightSearchPage);
  }

  private void checkBannerPositions(String bannerPositions, Page page) {  <-- error here
    //stuff
  }
}

I can work around it by casting flightSearchPage and flightResultPage to Page.

(2)

public final class SharedWebDrivers {

  private SharedWebDriver desktopDriver;
  private SharedWebDriver tabletDriver;

  public void preparedTabletDriver() {
    resize(tabletDriver, TABLET_WIDTH, TABLET_HEIGHT);
  }

  public void preparedDesktopDriver() {
    resize(desktopDriver, DESKTOP_WIDTH, DESKTOP_HEIGHT);
  }

  private static void resize(WebDriver webDriver, int width, int height) {  <-- error here
    //stuff
  }
}

I can work around this by changing the resize signature to use SharedWebDriver instead.

Discussion

  • Andreas Dangel

    Andreas Dangel - 2014-12-15

    I can't reproduce it with version 5.2.2 (see attached zip file).
    Do you use plain PMD or do you use PMD through ant/maven/gradle/IDE?

     

    Last edit: Andreas Dangel 2014-12-15
  • Andreas Dangel

    Andreas Dangel - 2014-12-15
    • status: open --> more-info-needed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-Next
     
  • Andreas Dangel

    Andreas Dangel - 2014-12-21
    • Milestone: PMD-5.2.3 --> PMD-Next
     
  • mingoto

    mingoto - 2014-12-23

    I get even more of these after upgrading to 5.2.3. I use PMD through gradle.

     
    • Andreas Dangel

      Andreas Dangel - 2014-12-23

      Hi, do you get the false positives also with the attached example (bug-1292.zip)? Could you please try this - and if you don't get false positives, could you provide me a better example please?
      Many thanks!

       
  • Andreas Dangel

    Andreas Dangel - 2015-04-01
    • Milestone: PMD-5.3.0 --> PMD-5.3.1
     
  • Andreas Dangel

    Andreas Dangel - 2015-04-20
    • Milestone: PMD-5.3.1 --> PMD-5.4.0
     
  • Andreas Dangel

    Andreas Dangel - 2015-10-04
    • Milestone: PMD-5.4.0 --> PMD-5.4.1
    • Ruleset / Rule: -->
     
  • Andreas Dangel

    Andreas Dangel - 2015-12-04
    • Milestone: PMD-5.4.1 --> PMD-5.5.0
     
  • Andreas Dangel

    Andreas Dangel - 2016-06-25
    • Milestone: PMD-5.5.0 --> New Tickets
     

Log in to post a comment.

MongoDB Logo MongoDB