GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] UnusedPrivateMethod false positive with static method and cast expression · Issue #3209 · pmd/pmd

[java] UnusedPrivateMethod false positive with static method and cast expression #3209

New issue
Copy link
New issue
Copy link
Closed
#3683
Closed
[java] UnusedPrivateMethod false positive with static method and cast expression#3209
#3683
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.42.0

Description

@adangel
adangel
opened on Apr 10, 2021
Issue body actions

Affects PMD Version: 6.33.0

Rule: UnusedPrivateMethod

Description:
The usage of the static method is not detected anymore (not sure, if these details are relevant).
The false positive was not reported with PMD 6.32.0.
Maybe this is a side-effect of fixing #3118

Code Sample demonstrating the issue:

Method declaration:

pmd/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedAssignmentRule.java

Line 909 in 30e841a

private static JVariableSymbol getVarIfUnaryAssignment(ASTUnaryExpression node) {

Method call:

pmd/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedAssignmentRule.java

Line 1396 in 30e841a

&& var.equals(ReachingDefsVisitor.getVarIfUnaryAssignment((ASTUnaryExpression) rhs));

Expected outcome:

  • Does PMD report a violation, where there shouldn't be one? -> false-positive

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]

Activity

  1. adangel
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on Apr 10, 2021
  2. adangel
    added a commit that references this issue on Apr 10, 2021

    Suppress PMD false positive with unused private method

    2f4bde2
  3. adangel commented on Dec 17, 2021

    @adangel
    adangel
    on Dec 17, 2021
    MemberAuthor
    More actions

    Testcase:

        <test-code>
            <description>[java] UnusedPrivateMethod false positive with static method and cast expression #3209</description>
            <expected-problems>0</expected-problems>
            <code><![CDATA[
    public class UnusedAssignmentRule {
        private static class ReachingDefsVisitor {
            private static String getVarIfUnaryAssignment(String node) {
                return null;
            }
        }
        public static class AssignmentEntry {
            final String var;
            final Object rhs;
            public boolean isUnaryReassign() {
                return rhs instanceof String
                    && var.equals(ReachingDefsVisitor.getVarIfUnaryAssignment((String) rhs));
            }
        }
    }
            ]]></code>
        </test-code>
  4. adangel commented on Dec 17, 2021

    @adangel
    adangel
    on Dec 17, 2021
    MemberAuthor
    More actions

    It's fixed by #3683 as well

  5. adangel
    added this to the 6.42.0 milestone on Dec 17, 2021
  6. adangel
    added 3 commits that reference this issue on Dec 17, 2021

    [java] UnusedPrivateMethod: Add test case for pmd#3209

    9c65913

    [doc] Update release notes (#3209, #3468, #3683)

    9d16215

    Merge pull request pmd#3683 from johnra2:3468-upm-inner-class

    14303f2
  7. adangel
    closed this as completedin #3683on Dec 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

      Milestone

      • 6.42.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.