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] UnusedPrivateField - false positive with Spring @SpyBean · Issue #4037 · pmd/pmd

[java] UnusedPrivateField - false positive with Spring @SpyBean #4037

New issue
Copy link
New issue
Copy link
Closed
#4100
Closed
[java] UnusedPrivateField - false positive with Spring @SpyBean#4037
#4100
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.50.0

Description

@ghost
ghost
opened on Jul 7, 2022

Affects PMD Version:6.47.0

Rule:UnusedPrivateField

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#unusedprivatefield

Description:
Hi, I found a false negative about the rule UnusedPrivateField, please read the following code example. In line 3, the code has an annotation @SpyBean, which means that the filed service could be used in testing. However, PMD reports a warning of this rule.

Besides, in src file, PMD has considered @MockBen, and it doesn't report identical warning for the field with MockBean. Hence, I think this is a false positive.

Code Sample demonstrating the issue:

import org.springframework.boot.test.mock.mockito.SpyBean;
public class C {
    @SpyBean
    private Service service;  // a false warning of this field
}

Expected outcome:

PMD reports a violation at line 4, but that's wrong. That's a false positive.

Running PMD through: [Maven]

Activity

  1. ghost added
    a:false-positivePMD flags a piece of code that is not problematic
    on Jul 7, 2022
  2. adangel
    changed the title [-]A false positive about the rule UnusedPrivateField[/-] [+][java] UnusedPrivateField - false positive with Mockito @SpyBean[/+] on Jul 7, 2022
  3. adangel
    changed the title [-][java] UnusedPrivateField - false positive with Mockito @SpyBean[/-] [+][java] UnusedPrivateField - false positive with Spring @SpyBean[/+] on Jul 7, 2022
  4. adangel
    added this to the 6.50.0 milestone on Sep 30, 2022
  5. adangel
    added a commit that references this issue on Sep 30, 2022

    [doc] Update release notes (pmd#4100, pmd#4033, pmd#4037)

    2105bde
  6. adangel
    closed this as completedin #4100on Sep 30, 2022
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.50.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.