Menu

#881 private final without setter is flagged

PMD-5.1.0
closed
pmd (543)
PMD
1-Blocker
Bug
2013-10-09
2009-07-07
No

If a field is declared private final, the BeanMembersShouldSerialize
rule fails if there is only a getter method. Adding a setter resolves
the problem, but of course the setter cannot set anything.

It seems the rule should not require a setter. Right?

Discussion

  • Jan Ruzicka

    Jan Ruzicka - 2009-08-19

    I'm running to the same problem. This comes for all POJ Data Holder classes, that have values assigned at construction and just read.

     
  • Anthony Whitford

    I am still witnessing this issue, even with PMD 5.0.5. Any chance that this can be resolved?

     
  • Anthony Whitford

    I think the fix is really simple...

    In pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/javabeans/BeanMembersShouldSerializeRule.java, change:

       if (!hasGetMethod || !hasSetMethod) {
    

    to:

       // Note that a Setter method is not applicable to a final variable...
       if (!hasGetMethod || (!decl.getAccessNodeParent().isFinal() && !hasSetMethod)) {
    
     
  • Andreas Dangel

    Andreas Dangel - 2013-10-09
    • status: open --> closed
    • assigned_to: Tom Copeland --> Andreas Dangel
    • Module: --> PMD
    • Milestone: --> PMD-5.1.0
    • Priority: 5 --> 1-Blocker
    • Type: --> Bug
    • Affects version: -->
     
  • Andreas Dangel

    Andreas Dangel - 2013-10-09
     

Log in to post a comment.