Added new rule
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1432 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -5,6 +5,41 @@
|
||||
These are new rules for the next release
|
||||
</description>
|
||||
|
||||
<rule name="ConstructorCallsOverridableMethodRule"
|
||||
message="Avoid calls to overridable methods during construction"
|
||||
class="net.sourceforge.pmd.rules.ConstructorCallsOverridableMethodRule">
|
||||
<description>
|
||||
Calling overridable methods during construction poses a risk of invoking methods on an
|
||||
incompletely constructed object. This situation can be difficult to discern.
|
||||
It may leave the sub-class unable to construct its superclass or forced to
|
||||
replicate the construction process completely within itself, losing the ability to call
|
||||
super(). If the default constructor contains a call to an overridable method,
|
||||
the subclass may be completely uninstantiable.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class SeniorClass {
|
||||
public SeniorClass(){
|
||||
toString(); //may throw NullPointerException if overridden
|
||||
}
|
||||
public String toString(){
|
||||
return "IAmSeniorClass";
|
||||
}
|
||||
}
|
||||
public class JuniorClass extends SeniorClass {
|
||||
private String name;
|
||||
public JuniorClass(){
|
||||
super(); //Automatic call leads to NullPointerException
|
||||
name = "JuniorClass";
|
||||
}
|
||||
public String toString(){
|
||||
return name;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="SymbolTableTestRule"
|
||||
message="test"
|
||||
|
Reference in New Issue
Block a user