A RetroSearch Logo

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

Search Query:

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

Do not flag fields in @Entity · Issue #3823 · pmd/pmd · GitHub

Affects PMD Version: 6.43.0

Rule: ImmutableField

Description:

JPA classes do not allow for final fields. The primary key fields (i.e., annotated with @javax.persistence.Id) are sometimes implemented as immutable (i.e., no setters). ImmutableField rule flags that these fields could be final. Please fix the rule to not operate on fields annotated with @javax.persistence.Id.

Code Sample demonstrating the issue:

@Entity
@Table(name = "my_table")
public class MyTable implements Serializable
{
   private static final long serialVersionUID = 1L;

   @Id
   @Column(name = "directory", nullable = false)
   private long m_id;  // PMD Violation: ImmutableField

   // other fields

   /**
    * For JPA
    */
   public MyTable()
   {
      // nothing to do
   }

   public long getId()
   {
      return m_id;
   }
}

Expected outcome:

PMD reports a violation at line private long m_id; // PMD Violation: ImmutableField, but that's wrong. That's a false positive.

Running PMD through: Eclipse PMD Plugin


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