Menu

#1216 AtLeastOneConstructor ignores classes with *any* methods

PMD-5.1.2
closed
PMD
4-Minor
Bug
5.1.1
2014-08-14
2014-07-01
No

java-controversial/AtLeastOneConstructor ignores classes that have any methods, not merely ones that have static methods. This is because it looks for whether the class has any methods with [@Static], which is still true for methods where @Static='false', rather than looking for whether the class has any methods with [@Static='true'], which should yield the desired behavior of only ignoring classes with a static method. Simply changing "[@Static]" to "[@Static='true']" in the xml for the xpath of this rule should correct it. Alternatively, altering the regex engine(s) such that [@Static] would evaluate to false if @Static='false' would also fix it, or if any of the versions already behaves so then changing this rule to that xpath version should fix it (barring other compatibility issues with that version).

Example code:

public class TestAtLeastOneConstructor {
    public void NotStatic() {
        System.out.println("This class should have a constructor");
    }
}

Should be reported by the following but isn't:

pmd -d TestAtLeastOneConstructor.java -R java-controversial/AtLeastOneConstructor

Discussion

  • Andreas Dangel

    Andreas Dangel - 2014-07-12
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-Next
     
  • Andreas Dangel

    Andreas Dangel - 2014-07-12

    This will be fixed with the next release.

     

Log in to post a comment.