A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/4037 below:

[java] UnusedPrivateField - false positive with Spring @SpyBean · Issue #4037 · pmd/pmd · GitHub

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]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4