Menu

#1349 VariableNamingConventions : underscore in final but at first position ?

New Tickets
more-info-needed
None
PMD
3-Major
Bug
2016-06-25
2015-05-06
No

private final String _projection;
private final String _projectionID;

=> These attributes are not in error with VariableNamingConventions as they are final.
It can be confusing as the underscore is in first position (due to private probably), and not in UPPER case.
=> final should be in UPPER case ?

Discussion

  • Andreas Dangel

    Andreas Dangel - 2015-05-09
    • status: open --> more-info-needed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-5.3.2
     
  • Andreas Dangel

    Andreas Dangel - 2015-05-09

    These attributes don't raise a violation. Are you suggesting, that they should?
    In terms of forcing final to be UPPER case - that's probably not a good idea - it would flag for existing code many, many violations.

    In your example the attributes are not static - only static final attributes are checked for being UPPER case.

    So, currently, the rule works as follows:

    • static and final: violation if not fully UPPER case
    • not final: violation if "_" is used in the name or if first character is a upper case character

    Essentially, any final attributes are ignored by this rule...

    However, we can extend the rule and add an additional parameter, to also check "final" parameters and apply the same rules as for non-final one. Would this be useful for you?

     
  • Denis SEMMAU

    Denis SEMMAU - 2015-05-20

    Well, actually the main problem is that _ should be used to separate words.
    In this case, the developer put an _ at the beginning (or at the end) of a variable name, because the variable is set as private, and not at all because the variable is static or final.

    So I think it would be a good idea to raise a bug if an undescore is in first or last position of a variable name. What do you think about that ?

    Well, it was mainly a suggestion, maybe it's not pertinent ...
    Regards,

     
  • Andreas Dangel

    Andreas Dangel - 2015-05-22
    • Milestone: PMD-5.3.2 --> PMD-5.4.0
    • Ruleset / Rule: -->
     
  • Andreas Dangel

    Andreas Dangel - 2015-10-04
    • Milestone: PMD-5.4.0 --> PMD-5.4.1
     
  • Andreas Dangel

    Andreas Dangel - 2015-12-04
    • Milestone: PMD-5.4.1 --> PMD-5.5.0
     
  • Andreas Dangel

    Andreas Dangel - 2016-06-25
    • Milestone: PMD-5.5.0 --> New Tickets
     

Log in to post a comment.