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] ImmutableField reports fields annotated with @GwtMock (GwtMockito) and @Spy (Mockito) · Issue #4004 · pmd/pmd

[java] ImmutableField reports fields annotated with @GwtMock (GwtMockito) and @Spy (Mockito) #4004

New issue
Copy link
New issue
Copy link
Closed
#4018
Closed
[java] ImmutableField reports fields annotated with @GwtMock (GwtMockito) and @Spy (Mockito)#4004
#4018
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.47.0

Description

@lgemeinhardt
lgemeinhardt
opened on Jun 9, 2022
Issue body actions

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");

Activity

  1. lgemeinhardt
    added
    a:bugPMD crashes or fails to analyse a file.
    on Jun 9, 2022
  2. adangel
    added this to the 6.47.0 milestone on Jun 23, 2022
  3. adangel
    added
    a:false-positivePMD flags a piece of code that is not problematic
    and removed
    a:bugPMD crashes or fails to analyse a file.
    on Jun 23, 2022
  4. adangel
    linked a pull request that will close this issue[java] Fix #4008 - ImmutableField FN with field assigned only in initializer #4018on Jun 23, 2022
  5. adangel
    added 2 commits that reference this issue on Jun 23, 2022

    [java] ImmutableField - add test case for GwtMockito and Spy (Mockito) (

    770e416

    [doc] Update release notes for PR pmd#4018

    520ca80
  6. adangel
    closed this as completedin #4018on Jun 23, 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.47.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.