A RetroSearch Logo

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

Search Query:

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

[java] ImmutableField reports fields annotated with @GwtMock (GwtMockito) and @Spy (Mockito) · Issue #4004 · pmd/pmd · GitHub

Affects PMD Version:
6.44.0, 6.45.0 and 6.46.0

Rule:
ImmutableField
https://pmd.github.io/pmd-6.46.0/pmd_rules_java_design.html#immutablefield

Description:
Similar to the issues #3874, #3981 and #3998, when annotating fields with Mockito @Spy annotation or GwtMockito (https://github.com/google/gwtmockito) @GwtMock annotation, PMD (starting from 6.44.0) will report "the field could be made final. It is only initialized in the declaration or constructor." However, the fields need to be non-final in order for the reflection.

Code Sample demonstrating the issue:

public class SomeTest {

    @com.google.gwtmockito.GwtMock
    private String someMock;

    @org.mockito.Spy
    private String someSpy;

}

Expected outcome:
PMD reports a violation for someMock + someSpy, but that's wrong. That's a false positive.

Running PMD through:
Ant

Possible fix:
Please simple add this "excludes" into https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java#L47 (defaultSuppressionAnnotations method), like:

defaultValues.add("org.mockito.Spy");
defaultValues.add("com.google.gwtmockito.GwtMock");

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