diff --git a/pmd-java/src/main/resources/category/java/design.xml b/pmd-java/src/main/resources/category/java/design.xml index c5f065eef8..3008880e5a 100644 --- a/pmd-java/src/main/resources/category/java/design.xml +++ b/pmd-java/src/main/resources/category/java/design.xml @@ -904,15 +904,30 @@ public class Foo { +Identifies beans, that don't follow the [JavaBeans API specification](https://download.oracle.com/otndocs/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/). +Each non-static field should have both a getter and a setter method. If the field is just used internally and is not +a bean property, then the field should be marked as `transient`. + +The rule verifies that the type of the field is the same as the result type of the getter. And that this type matches +the type used in the setter. + +The rule also checks, that there is a no-arg or default constructor available. + +Optionally the rule also verifies, that the bean implements `java.io.Serializable`. While this is a requirement for the +original JavaBeans specification, frameworks nowadays don't strictly require this anymore. + +In order to avoid many false positives in classes that are not beans, the rule needs to be explicitly +enabled by configuring the property `packages`. 3 + + + + + diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/InvalidJavaBean.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/InvalidJavaBean.xml index 51dc6a72cf..ef1d4d30d1 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/InvalidJavaBean.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/InvalidJavaBean.xml @@ -7,14 +7,14 @@ Example code true - 2 - 1,2 + 2,3 The bean 'MyBean' does not implement java.io.Serializable. The bean 'MyBean' is missing a setter for property 'Label'.