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
Affects PMD Version: 6.43.0
Rule: ImmutableField
Description:
JPA classes do not allow for
finalfields. The primary key fields (i.e., annotated with@javax.persistence.Id) are sometimes implemented as immutable (i.e., no setters).ImmutableFieldrule flags that these fields could befinal. Please fix the rule to not operate on fields annotated with@javax.persistence.Id.Code Sample demonstrating the issue:
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