A RetroSearch Logo

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

Search Query:

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

[java] ImmutableField reports fields annotated with @Captor (Mockito) · Issue #3998 · pmd/pmd · GitHub

Affects PMD Version:
6.46.0

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

Description:
#3874 is not completely fixed with PMD 6.46.0. For example, fields annotated with Mockito's @Captor. Likely also effects other Mockito annotations such as @Spy.

Code Sample demonstrating the issue:

@ExtendWith(MockitoExtension.class)
class SomeTest {
    @Captor
    private ArgumentCaptor<String> argCaptor;
    @Mock
    private List<String> mockList;

    @Test
    void testCap() {
        mockList.add("junk");
        verify(mockList).add(argCaptor.capture());
        assertEquals("junk", argCaptor.getValue());
    }
}

Expected outcome:

PMD reports a violation for argCaptor, 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