Skip to content

[java] False positive FinalFieldCouldBeStatic when using lombok Builder.Default #2708

Closed

Description

@ollieabbey

Affects PMD Version:

maven-pmd-plugin version 3.13.0 (PMD 6.21.0)

Rule: FinalFieldCouldBeStatic

Description:

Private final fields annotated with lombok @Builder.Default trigger FinalFieldCouldBeStatic, even though they're not behaving as constants.

Code Sample demonstrating the issue:

package com.example;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class ExampleClass {

    @Builder.Default
    private final long exampleField = 0L;
}

Output

PMD Failure: com.example.ExampleClass:11 Rule:FinalFieldCouldBeStatic Priority:3 This final field could be made static.

Running PMD through: [Maven]

Activity

  1. added
    a:bug
    on Aug 8, 2020
  2. added
    a:false-positive
    and removed
    a:bug
    on Aug 23, 2020
  3. ollieabbey commented on Aug 27, 2020

    @ollieabbey
    ContributorAuthor

    I've created #2747 to fix this.

    @adangel if you wouldn't mind reviewing and letting me know if there's anything that needs changing, I can do so. Cheers!

  4. added this to the 6.28.0 milestone on Sep 6, 2020
  5. blacelle commented on Oct 26, 2023

    @blacelle

    This issue still happens with the used annotation is @Default instead of @Builder.Default (and relevant imports statements).

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-positive

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions