<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Rules">
    <description>PMD Plugin preferences rule set</description>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Use the correct logging statement for logging exceptions" name="UseCorrectExceptionLogging">
        <description>
To make sure the full stacktrace is printed out, use the logging statement with 2 arguments: a String and a Throwable.
        </description>
        <example><![CDATA[
public class Main {
 private static final Log _LOG = LogFactory.getLog( Main.class );
 void bar() {
  try {
  } catch( Exception e ) {
   _LOG.error( e ); //Wrong!
  } catch( OtherException oe ) {
   _LOG.error( oe.getMessage(), oe ); //Correct
  }
 }
}
]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
//CatchStatement/Block/BlockStatement/Statement/StatementExpression
/PrimaryExpression[PrimaryPrefix/Name[starts-with(@Image,
concat(ancestor::ClassOrInterfaceDeclaration/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration
[Type//ClassOrInterfaceType[@Image='Log']]
/VariableDeclarator/VariableDeclaratorId/@Image, '.'))]]
[PrimarySuffix/Arguments[@ArgumentCount='1']]
[PrimarySuffix/Arguments//Name/@Image = ancestor::CatchStatement/FormalParameter/VariableDeclaratorId/@Image]
         ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Logger should be defined private static final and have the correct class" name="ProperLogger">
        <description>
A logger should normally be defined private static final and have the correct class.
Private final Log log; is also allowed for rare cases where loggers need to be passed
around, with the restriction that the logger needs to be passed into the constructor.
             </description>
        <example><![CDATA[
 
 public class Foo {
 // right
  private static final Log LOG = LogFactory.getLog(Foo.class);
 // wrong
 protected Log LOG = LogFactory.getLog(Testclass.class);
}
 
            ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
     
//ClassOrInterfaceBodyDeclaration[FieldDeclaration//ClassOrInterfaceType[@Image='Log']
 and
 not(FieldDeclaration[@Final='true'][@Static='true'][@Private='true'][.//VariableDeclaratorId[@Image=$staticLoggerName]]
 //ArgumentList//ClassOrInterfaceType/@Image = ancestor::ClassOrInterfaceDeclaration/@Image)
 and
 not(FieldDeclaration[@Final='true'][@Private='true'][.//VariableDeclaratorId[@Image='log']]
 [count(.//VariableInitializer)=0]
 [ancestor::ClassOrInterfaceBody//StatementExpression[.//PrimaryExpression/descendant::*[@Image='log']][count(.//AllocationExpression)=0]]
 )]
     
                     ]]></value>
            </property>
            <property name="staticLoggerName" value="LOG"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid variables with short names like {0}" name="ShortVariable">
        <description>
Detects when a field, local, or parameter has a very short name.
    </description>
        <example><![CDATA[

public class Something {
  private int q = 15; // VIOLATION - Field
  public static void main( String as[] ) {  // VIOLATION - Formal
    int r = 20 + q; // VIOLATION - Local
    for (int i = 0; i < 10; i++) { // Not a Violation (inside FOR)
      r += q;
    }
  }
}

    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                  
//VariableDeclaratorId[string-length(@Image) < 3]
 [not(ancestor::ForInit)]
 [not((ancestor::FormalParameter) and (ancestor::TryStatement))]
                  
              ]]></value>
            </property>
            <property name="pluginname" value="true"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid excessively long variable names like {0}" name="LongVariable">
        <description>
Detects when a field, formal or local variable is declared with a long name.
    </description>
        <example><![CDATA[

public class Something {
  int reallyLongIntName = -3;  // VIOLATION - Field
  public static void main( String argumentsList[] ) { // VIOLATION - Formal
    int otherReallyLongName = -5; // VIOLATION - Local
    for (int interestingIntIndex = 0;  // VIOLATION - For
             interestingIntIndex < 10;
             interestingIntIndex ++ ) {
    }
}

    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                  
//VariableDeclaratorId[string-length(@Image) > $minimum]
                  
              ]]></value>
            </property>
            <property name="minimum" value="17"/>
            <property name="pluginname" value="true"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid using short method names" name="ShortMethodName">
        <description>
Detects when very short method names are used.
     </description>
        <example><![CDATA[

public class ShortMethod {
  public void a( int i ) { // Violation
  }
}

     ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                  
//MethodDeclarator[string-length(@Image) < 3]
                  
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.VariableNamingConventions" message="{0} variable {1} should begin with {2}" name="VariableNamingConventions">
        <description>
A variable naming conventions rule - customize this to your liking.  Currently, it
 checks for final variables that should be fully capitalized and non-final variables
 that should not include underscores.
        </description>
        <example><![CDATA[

public class Foo {
 public static final int MY_NUM = 0;
 public String myTest = "";
 DataModule dmTest = new DataModule();
}

        ]]></example>
        <priority>1</priority>
        <properties>
            <property name="staticPrefix" value=""/>
            <property name="staticSuffix" value=""/>
            <property name="memberPrefix" value=""/>
            <property name="memberSuffix" value=""/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.MethodNamingConventions" message="Method name does not begin with a lower case character." name="MethodNamingConventions">
        <description>
Method names should always begin with a lower case character, and should not contain underscores.
          </description>
        <example><![CDATA[

public class Foo {
 public void fooStuff() {
 }
}

          ]]></example>
        <priority>1</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.ClassNamingConventions" message="Class names should begin with an uppercase character" name="ClassNamingConventions">
        <description>
Class names should always begin with an upper case character.
      </description>
        <example><![CDATA[

public class Foo {}

      ]]></example>
        <priority>1</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Abstract classes should be named 'AbstractXXX'" name="AbstractNaming">
        <description>
Abstract classes should be named 'AbstractXXX'.
       </description>
        <example><![CDATA[

public abstract class Foo { // should be AbstractFoo
}

       ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                    
//ClassOrInterfaceDeclaration
 [@Abstract='true' and @Interface='false']
 [not (starts-with(@Image,'Abstract'))]
                    
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.naming.AvoidDollarSigns" message="Avoid using dollar signs in variable/method/class/interface names" name="AvoidDollarSigns">
        <description>
Avoid using dollar signs in variable/method/class/interface names.
       </description>
        <example><![CDATA[
   
 public class Fo$o {  // yikes!
 }
   
       ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.MethodWithSameNameAsEnclosingClass" message="Classes should not have non-constructor methods with the same name as the class" name="MethodWithSameNameAsEnclosingClass">
        <description>
Non-constructor methods should not have the same name as the enclosing class.
       </description>
        <example><![CDATA[
    
public class MyClass {
 // this is bad because it is a method
 public void MyClass() {}
 // this is OK because it is a constructor
 public MyClass() {}
}
    
       ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.naming.SuspiciousHashcodeMethodName" message="The method name and return type are suspiciously close to hashCode()" name="SuspiciousHashcodeMethodName">
        <description>
The method name and return type are suspiciously close to hashCode(), which
may mean you are intending to override the hashCode() method.
       </description>
        <example><![CDATA[
    
public class Foo {
 public int hashcode() {
 // oops, this probably was supposed to be hashCode
 }
}
    
       ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="The field name indicates a constant but its modifiers do not" name="SuspiciousConstantFieldName">
        <description>
A field name is all in uppercase characters, which in Sun's Java naming
conventions indicate a constant. However, the field is not final.
       </description>
        <example><![CDATA[
    
public class Foo {
 // this is bad, since someone could accidentally
 // do PI = 2.71828; which is actualy e
 // final double PI = 3.16; is ok
 double PI = 3.16;
}
    
       ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//ClassOrInterfaceDeclaration[@Interface='false']
 /ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration
  [@Final='false']
  [VariableDeclarator/VariableDeclaratorId[upper-case(@Image)=@Image]]
 
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="The method name and parameter number are suspiciously close to equals(Object)" name="SuspiciousEqualsMethodName">
        <description>
The method name and parameter number are suspiciously close to
equals(Object), which may mean you are intending to override the equals(Object)
method.
        </description>
        <example><![CDATA[
        
public class Foo {
 public int equals(Object o) {
 // oops, this probably was supposed to be boolean equals
 }
 public boolean equals(String s) {
 // oops, this probably was supposed to be equals(Object)
 }
}
        
        ]]></example>
        <priority>2</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
        
//MethodDeclarator[
(
@Image = 'equals'
  and count(FormalParameters/*) = 1
  and not (FormalParameters/FormalParameter/Type/ReferenceType/ClassOrInterfaceType
   [@Image = 'Object' or @Image = 'java.lang.Object'])
)
or
@Image='equal'
 and count(FormalParameters/*) = 1
 and (FormalParameters/FormalParameter/Type/ReferenceType/ClassOrInterfaceType
  [@Image = 'Object' or @Image = 'java.lang.Object'])

]
        
                    ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.AvoidFieldNameMatchingTypeName" message="It is somewhat confusing to have a field name matching the declaring class name" name="AvoidFieldNameMatchingTypeName">
        <description>
It is somewhat confusing to have a field name matching the declaring class name.
This probably means that type and or field names could be more precise.
      </description>
        <example><![CDATA[

public class Foo extends Bar {
 // There's probably a better name for foo
 int foo;
}

      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.AvoidFieldNameMatchingMethodName" message="It is somewhat confusing to have a field name with the same name as a method" name="AvoidFieldNameMatchingMethodName">
        <description>
It is somewhat confusing to have a field name with the same name as a method.
While this is totally legal, having information (field) and actions (method) is
not clear naming.
      </description>
        <example><![CDATA[

public class Foo {
	Object bar;
	// bar is data or an action or both?
	void bar() {
	}
}

      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="All classes and interfaces must belong to a named package" name="NoPackage">
        <description>
Detects when a class or interface does not have a package definition.
    </description>
        <example><![CDATA[

// no package declaration
public class ClassInDefaultPackage {
}

    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                  
//ClassOrInterfaceDeclaration[count(preceding::PackageDeclaration) = 0]
                  
              ]]></value>
            </property>
            <property name="pluginname" value="true"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Package name contains upper case characters" name="PackageCase">
        <description>
    Detects when a package definition contains upper case characters.
        </description>
        <example><![CDATA[
    
package com.MyCompany;  // <- should be lower case name
public class SomeClass {
}
    
        ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                      
//PackageDeclaration/Name[lower-case(@Image)!=@Image]
                      
                  ]]></value>
            </property>
            <property name="pluginname" value="true"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid naming non-fields with the prefix 'm_'" name="MisleadingVariableName">
        <description>
Detects when a non-field has a name starting with 'm_'.  This usually
indicates a field and thus is confusing.
      </description>
        <example><![CDATA[
  
  public class Foo {
    private int m_foo; // OK
    public void bar(String m_baz) {  // Bad
      int m_boz = 42; // Bad
    }
  }
  
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                    
//VariableDeclaratorId
[starts-with(@Image, 'm_')]
[not (../../../FieldDeclaration)]
                    
                ]]></value>
            </property>
            <property name="pluginname" value="true"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="A 'getX()' method which returns a boolean should be named 'isX()'" name="BooleanGetMethodName">
        <description>
Looks for methods named 'getX()' with 'boolean' as the return type. The convention
is to name these methods 'isX()'.
        </description>
        <example><![CDATA[
            
public boolean getFoo(); // bad
public boolean isFoo(); // ok
public boolean getFoo(boolean bar); // ok, unless checkParameterizedMethods=true
     ]]></example>
        <priority>4</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                    
//MethodDeclaration[
MethodDeclarator[count(FormalParameters/FormalParameter) = 0 or $checkParameterizedMethods = 'true']
                [starts-with(@Image, 'get')]
and
ResultType/Type/PrimitiveType[@Image = 'boolean']
]

                ]]></value>
            </property>
            <property name="checkParameterizedMethods" value="false"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Consider replacing this Vector with the newer java.util.List" name="ReplaceVectorWithList">
        <description>
  Consider replacing Vector usages with the newer java.util.ArrayList if expensive threadsafe operation is not required.
  </description>
        <example><![CDATA[

public class Foo {
 void bar() {
    Vector v = new Vector();
 }
}

  ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//Type/ReferenceType/ClassOrInterfaceType[@Image='Vector']
 
    ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Consider replacing this Hashtable with the newer java.util.Map" name="ReplaceHashtableWithMap">
        <description>
      Consider replacing this Hashtable with the newer java.util.Map
      </description>
        <example><![CDATA[
    
    public class Foo {
     void bar() {
        Hashtable h = new Hashtable();
     }
    }
    
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//Type/ReferenceType/ClassOrInterfaceType[@Image='Hashtable']
     
        ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Consider replacing this Enumeration with the newer java.util.Iterator" name="ReplaceEnumerationWithIterator">
        <description>
      Consider replacing this Enumeration with the newer java.util.Iterator
      </description>
        <example><![CDATA[
    
public class Foo implements Enumeration {
    private int x = 42;
    public boolean hasMoreElements() {
        return true;
    }
    public Object nextElement() {
        return String.valueOf(i++);
    }
}
    
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//ImplementsList/ClassOrInterfaceType[@Image='Enumeration']
     
        ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid using enum as an identifier; it's a reserved word in JDK 1.5" name="AvoidEnumAsIdentifier">
        <description>Finds all places where 'enum' is used as an identifier.</description>
        <example><![CDATA[
  
    public class A {
        public  class foo {
            String enum = "foo";
        }
    }
  
      ]]></example>
        <priority>2</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                  
//VariableDeclaratorId[@Image='enum']
                  
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid using assert as an identifier; it's a reserved word in JDK 1.4" name="AvoidAssertAsIdentifier">
        <description>Finds all places where 'assert' is used as an identifier.</description>
        <example><![CDATA[
  
    public class A {
        public  class foo {
            String assert = "foo";
        }
    }
  
      ]]></example>
        <priority>2</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                  
//VariableDeclaratorId[@Image='assert']
                  
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid instantiating Integer objects. Call Integer.valueOf() instead." name="IntegerInstantiation">
        <description>In JDK 1.5, calling new Integer() causes memory allocation.  Integer.valueOf() is more memory friendly.</description>
        <example><![CDATA[
  
public class Foo {
 private Integer i = new Integer(0); // change to Integer i = Integer.valueOf(0);
}
   
      ]]></example>
        <priority>2</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                  
//PrimaryPrefix
 /AllocationExpression
  [not (ArrayDimsAndInits)
   and (ClassOrInterfaceType/@Image='Integer'
    or ClassOrInterfaceType/@Image='java.lang.Integer')]
                  
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid instantiating Byte objects. Call Byte.valueOf() instead" name="ByteInstantiation">
        <description>
              In JDK 1.5, calling new Byte() causes memory allocation. Byte.valueOf() is more memory friendly.
          </description>
        <example><![CDATA[

public class Foo {
private Byte i = new Byte(0); // change to Byte i =
Byte.valueOf(0);
}

     ]]></example>
        <priority>2</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
          
//PrimaryPrefix/AllocationExpression
[not (ArrayDimsAndInits)
and (ClassOrInterfaceType/@Image='Byte'
or ClassOrInterfaceType/@Image='java.lang.Byte')]
          
          ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid instantiating Short objects. Call Short.valueOf() instead" name="ShortInstantiation">
        <description>In JDK 1.5, calling new Short() causes memory allocation. Short.valueOf() is more memory friendly.
          </description>
        <example><![CDATA[

public class Foo {
private Short i = new Short(0); // change to Short i =
Short.valueOf(0);
}

          ]]></example>
        <priority>2</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//PrimaryPrefix
/AllocationExpression
[not (ArrayDimsAndInits)
and (ClassOrInterfaceType/@Image='Short'
or ClassOrInterfaceType/@Image='java.lang.Short')]

          ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid instantiating Long objects.Call Long.valueOf() instead" name="LongInstantiation">
        <description>In JDK 1.5, calling new Long() causes memory allocation. Long.valueOf() is more memory friendly.</description>
        <example><![CDATA[

public class Foo {
private Long i = new Long(0); // change to Long i =
Long.valueOf(0);
}

    ]]></example>
        <priority>2</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//PrimaryPrefix
/AllocationExpression
[not (ArrayDimsAndInits)
and (ClassOrInterfaceType/@Image='Long'
or ClassOrInterfaceType/@Image='java.lang.Long')]

    ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="JUnit 4 tests that set up tests should use the @Before annotation" name="JUnit4TestShouldUseBeforeAnnotation">
        <description>
In JUnit 3, the setUp method was used to set up all data entities required in running tests. JUnit 4 skips the setUp method 
and executes all methods annotated with @Before before all tests
      </description>
        <example><![CDATA[

public class MyTest {
    public void setUp() {
        bad();
    }
}
public class MyTest2 {
    @Before public void setUp() {
        good();
    }
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//ClassOrInterfaceBodyDeclaration[MethodDeclaration/MethodDeclarator[@Image='setUp']]
[count(Annotation/MarkerAnnotation/Name[@Image='Before'])=0]

              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="JUnit 4 tests that clean up tests should use the @After annotation" name="JUnit4TestShouldUseAfterAnnotation">
        <description>
In JUnit 3, the tearDown method was used to clean up all data entities required in running tests. JUnit 4 skips the tearDown method 
and executes all methods annotated with @After after running each test
      </description>
        <example><![CDATA[

public class MyTest {
    public void tearDown() {
        bad();
    }
}
public class MyTest2 {
    @After public void tearDown() {
        good();
    }
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//ClassOrInterfaceBodyDeclaration[MethodDeclaration/MethodDeclarator[@Image='tearDown']]
[count(Annotation/MarkerAnnotation/Name[@Image='After'])=0]

              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="JUnit 4 tests that execute tests should use the @Test annotation" name="JUnit4TestShouldUseTestAnnotation">
        <description>
In JUnit 3, the framework executed all methods which started with the word test as a unit test. In JUnit 4, only methods annotated
with the @Test annotation are executed.
      </description>
        <example><![CDATA[

public class MyTest {
    public void testBad() {
        doSomething();
    }

	@Test
    public void testGood() {
        doSomething();
    }
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//ClassOrInterfaceBodyDeclaration[MethodDeclaration/MethodDeclarator[starts-with(@Image,'test')]]
[count(Annotation//Name[@Image='Test'])=0]

              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="JUnit 4 indicates test suites via annotations, not the suite method." name="JUnit4SuitesShouldUseSuiteAnnotation">
        <description>
In JUnit 3, test suites are indicated by the suite() method. In JUnit 4, suites are indicated
through the @RunWith(Suite.class) annotation.
      </description>
        <example><![CDATA[

public class BadExample extends TestCase{

    public static Test suite(){
    	return new Suite();
    }
}

@RunWith(Suite.class)
@SuiteClasses( { TestOne.class, TestTwo.class })
public class GoodTest {
}
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//ClassOrInterfaceBodyDeclaration[MethodDeclaration/MethodDeclarator[@Image='suite']]
[MethodDeclaration/ResultType/Type/ReferenceType/ClassOrInterfaceType[@Image='Test' or @Image = 'junit.framework.Test']]
[not(MethodDeclaration/Block//ClassOrInterfaceType[@Image='JUnit4TestAdapter'])]

              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.migration.JUnitUseExpected" message="In JUnit4, use the @Test(expected) annotation to denote tests that should throw exceptions" name="JUnitUseExpected">
        <description/>
        <example><![CDATA[

public class MyTest {
	@Test
    public void testBad() {
        try {
            doSomething();
            fail("should have thrown an exception");
        } catch (Exception e) {
        }
    }

	@Test(expected=Exception.class)
    public void testGood() {
        doSomething();
    }
}

      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid unnecessary constructors - the compiler will generate these for you" name="UnnecessaryConstructor">
        <description>
This rule detects when a constructor is not necessary; i.e., when there's only one constructor,
it's public, has an empty body, and takes no arguments.
      </description>
        <example><![CDATA[
  
public class Foo {
 public Foo() {}
}
  
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                    
//ClassOrInterfaceBody[count(ClassOrInterfaceBodyDeclaration/ConstructorDeclaration)=1]
/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration
[@Public='true']
[not(FormalParameters/*)]
[not(BlockStatement)]
[not(NameList)]
[count(ExplicitConstructorInvocation/Arguments/ArgumentList/Expression)=0]
                    
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.NullAssignmentRule" message="Assigning an Object to null is a code smell.  Consider refactoring." name="NullAssignment">
        <description>
 Assigning a "null" to a variable (outside of its declaration) is usually
 bad form.  Some times, the assignment is an indication that the programmer doesn't
 completely understand what is going on in the code.  NOTE: This sort of assignment
 may in rare cases be useful to encourage garbage collection.  If that's what you're using
 it for, by all means, disregard this rule :-)
      </description>
        <example><![CDATA[
 
 public class Foo {
   public void bar() {
     Object x = null; // This is OK.
     x = new Object();
     // Big, complex piece of code here.
     x = null; // This is BAD.
     // Big, complex piece of code here.
   }
 }

 
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.OnlyOneReturnRule" message="A method should have only one exit point, and that should be the last statement in the method" name="OnlyOneReturn">
        <description>
A method should have only one exit point, and that should be the last statement in the method.
     </description>
        <example><![CDATA[
 
 public class OneReturnOnly1 {
  public void foo(int x) {
   if (x > 0) {
    return "hey";   // oops, multiple exit points!
   }
   return "hi";
  }
 }
 
     ]]></example>
        <priority>5</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.UnusedModifier" message="Avoid modifiers which are implied by the context" name="UnusedModifier">
        <description>
 Fields in interfaces are automatically public static final, and
 methods are public abstract.
 Classes or interfaces nested in an interface are automatically public
 and static (all nested interfaces are automatically static).
 For historical reasons, modifiers which are implied by the context
 are accepted by the compiler, but are superfluous.
     </description>
        <example><![CDATA[
 
public interface Foo {
 public abstract void bar(); // both abstract and public are ignored by the compiler
 public static final int X = 0; // public, static, and final all ignored
 public static class Bar {} // public, static ignored
 public static interface Baz {} // ditto
}
public class Bar {
 public static interface Baz {} // static ignored
}
 
     ]]></example>
        <priority>5</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.AssignmentInOperand" message="Avoid assignments in operands" name="AssignmentInOperand">
        <description>
Avoid assignments in operands; this can make code more complicated and harder to read.
  </description>
        <example><![CDATA[
  
public class Foo {
 public void bar() {
  int x = 2;
  if ((x = getX()) == 3) {
   System.out.println("3!");
  }
 }
 private int getX() {
  return 3;
 }
}
  
  ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Each class should declare at least one constructor" name="AtLeastOneConstructor">
        <description>
Each class should declare at least one constructor.
  </description>
        <example><![CDATA[
  
public class Foo {
 // no constructor!  not good!
}
  
  ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
              
//ClassOrInterfaceDeclaration[
	not(ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration)
	and
	(@Static = 'false')
	and
	(count(./descendant::MethodDeclaration[@Static]) < 1)
]
	[@Interface='false']

          ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.imports.DontImportSun" message="Avoid importing anything from the 'sun.*' packages" name="DontImportSun">
        <description>
Avoid importing anything from the 'sun.*' packages.  These packages are not portable and are likely to change.
       </description>
        <example><![CDATA[

import sun.misc.foo;
public class Foo {}

       ]]></example>
        <priority>4</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.SuspiciousOctalEscape" message="Suspicious decimal characters following octal escape in string literal" name="SuspiciousOctalEscape">
        <description>
A suspicious octal escape sequence was found inside a String literal.
The Java language specification (section 3.10.6) says an octal
escape sequence inside a literal String shall consist of a backslash
followed by:

   OctalDigit | OctalDigit OctalDigit | ZeroToThree OctalDigit OctalDigit

Any octal escape sequence followed by non-octal digits can be confusing,
e.g. "\038" is interpreted as the octal escape sequence "\03" followed by
the literal character "8".
      </description>
        <example><![CDATA[

public class Foo {
 public void foo() {
  // interpreted as octal 12, followed by character '8'
  System.out.println("suspicious: \128");
 }
}

      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="It is a good practice to call super() in a constructor" name="CallSuperInConstructor">
        <description>
It is a good practice to call super() in a constructor. If super() is not called but
 another constructor (such as an overloaded constructor) is called, this rule will not report it.
      </description>
        <example><![CDATA[

public class Foo extends Bar{
 public Foo() {
  // call the constructor of Bar
  super();
 }
 public Foo(int code) {
  // do something with code
  this();
  // no problem with this
 }
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//ClassOrInterfaceDeclaration[ count (ExtendsList/*) > 0 ]
/ClassOrInterfaceBody
 /ClassOrInterfaceBodyDeclaration
 /ConstructorDeclaration[ count (.//ExplicitConstructorInvocation)=0 ]
    
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="This statement may have some unnecessary parentheses" name="UnnecessaryParentheses">
        <description>
Sometimes expressions are wrapped in unnecessary parentheses,
making them look like a function call.
      </description>
        <example><![CDATA[
  public class Foo {
      boolean bar() {
          return (true);
      }
  }
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                  
//ReturnStatement
          /Expression
           /PrimaryExpression
            /PrimaryPrefix
             /Expression[count(*)=1]
              /PrimaryExpression
              /PrimaryPrefix
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Use explicit scoping instead of the default package private level" name="DefaultPackage">
        <description>
Use explicit scoping instead of the default package private level.
        </description>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
//ClassOrInterfaceDeclaration[@Interface='false']
/ClassOrInterfaceBody
/ClassOrInterfaceBodyDeclaration
[
FieldDeclaration[@PackagePrivate='true']
or MethodDeclaration[@PackagePrivate='true']
]
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Use bitwise inversion to invert boolean values" name="BooleanInversion">
        <description>
Use bitwise inversion to invert boolean values - it's the fastest way to do this.
See http://www.javaspecialists.co.za/archive/newsletter.do?issue=042&amp;locale=en_US for specific details
      </description>
        <example><![CDATA[
  
public class Foo {
 public void main(bar) {
  boolean b = true;
  b = !b; // slow
  b ^= true; // fast
 }
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//AssignmentOperator[@Image="="]/../Expression/UnaryExpressionNotPlusMinus[@Image="!"]

             ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.dfa.DaaRule" dfa="true" message="Found ''{0}''-anomaly for variable ''{1}'' (lines ''{2}''-''{3}'')." name="DataflowAnomalyAnalysis">
        <description>The dataflow analysis tracks local definitions, undefinitions and references to variables on different paths on the data flow.
From those informations there can be found various problems.

1. UR - Anomaly: There is a reference to a variable that was not defined before. This is a bug and leads to an error.
2. DU - Anomaly: A recently defined variable is undefined. These anomalies may appear in normal source text.
3. DD - Anomaly: A recently defined variable is redefined. This is ominous but don't have to be a bug.
          </description>
        <example><![CDATA[

public class Foo {
    public void foo() {
	 int buz = 5;
	 buz = 6; // redefinition of buz -> dd-anomaly
	 foo(buz);
	 buz = 2;
    } // buz is undefined when leaving scope -> du-anomaly
}

          ]]></example>
        <priority>5</priority>
        <properties>
            <property name="maxpaths" value="1000"/>
            <property name="maxviolations" value="100"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid using final local variables, turn them into fields" name="AvoidFinalLocalVariable">
        <description>
Avoid using final local variables, turn them into fields.
         </description>
        <example><![CDATA[
public class MyClass {
    public void foo() {
        final String finalLocalVariable;
    }
}
	     ]]></example>
        <priority>5</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
//LocalVariableDeclaration[@Final = 'true']
	             ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Do not use the short type" name="AvoidUsingShortType">
        <description>
            
            Java uses the short type to reduce memory usage, not to optimize calculation. On the contrary, the jvm does not has an
            arithmetic capabilities with the type short. So, the P-code msut convert the short into int, then do the proper caculation
            and then again, convert int to short. So, use of the 'short' type may have a great effect on memory usage.
            
        </description>
        <example><![CDATA[
            
    public class UsingShort
    {
        private short doNotUseShort = 0;

		public UsingShort() {
			short shouldNotBeUsed = 1;
			doNotUseShort += shouldNotBeUsed;
		}
 	}
 			
 		]]></example>
        <priority>1</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                    
            //PrimitiveType[@Image = 'short']
                    
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Use of modifier volatile is not recommended." name="AvoidUsingVolatile">
        <description>
            
Use of the keyword 'volatile' is general used to fine tune a Java application, and therefore, requires
a good expertise of the Java Memory Model. Morover, its range of action is somewhat misknown. Therefore,
the volatile keyword should not be used for maintenance purpose and portability.
            
        </description>
        <example><![CDATA[
			
				public class ThrDeux {
					private volatile String var;

				}
			
		]]></example>
        <priority>2</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                    
                        //FieldDeclaration[
                                contains(@Volatile,'true')
                        ]
                    
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="The use of native code is not recommended." name="AvoidUsingNativeCode">
        <description>
            
                As JVM and Java language offer already many help in creating application, it should be
                very rare to have to rely on non-java code. Even though, it is rare to actually have to
                use Java Native Interface (JNI). As the use of JNI make application less portable, and
                harder to maintain, it is not recommended.
            
        </description>
        <example><![CDATA[
            
                public class SomeJNIClass {
                        public SomeJNIClass() {
                                System.loadLibrary("nativelib");
                        }

                        static {
                             System.loadLibrary("nativelib");
                        }

                        public void invalidCallsInMethod() throws SecurityException, NoSuchMethodException {
                                System.loadLibrary("nativelib");
                        }
                }
            
        ]]></example>
        <priority>2</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                    
                        //Name[starts-with(@Image,'System.loadLibrary')]
                    
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="You should modify visibility of class or methods using getDeclaredConstructors(), getDeclaredConstructor(Class[]), setAccessible() or PrivilegedAction." name="AvoidAccessibilityAlteration">
        <description>
            
            Methods such as getDeclaredConstructors(), getDeclaredConstructor(Class[]) and setAccessible(),
            as the interface PrivilegedAction, allow to alter, at runtime, the visilibilty of variable, classes, or
            methods, even if they are private. Obviously, no one should do so, as such behavior is against everything
            encapsulation principal stands for.
            
        </description>
        <example><![CDATA[
            

			import java.lang.reflect.AccessibleObject;
			import java.lang.reflect.Method;
			import java.security.PrivilegedAction;

			public class Violation {
				public void invalidCallsInMethod() throws SecurityException, NoSuchMethodException {
					// Possible call to forbidden getDeclaredConstructors
					Class[] arrayOfClass = new Class[1];
					this.getClass().getDeclaredConstructors();
					this.getClass().getDeclaredConstructor(arrayOfClass);
					Class clazz = this.getClass();
					clazz.getDeclaredConstructor(arrayOfClass);
					clazz.getDeclaredConstructors();

					// Possible call to forbidden setAccessible
					clazz.getMethod("", arrayOfClass).setAccessible(false);
					AccessibleObject.setAccessible(null, false);
					Method.setAccessible(null, false);
					Method[] methodsArray = clazz.getMethods();
					int nbMethod;
					for ( nbMethod = 0; nbMethod < methodsArray.length; nbMethod++ ) {
						methodsArray[nbMethod].setAccessible(false);
					}

					// Possible call to forbidden PrivilegedAction
					PrivilegedAction priv = (PrivilegedAction) new Object(); priv.run();
				}
			}
					
			]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                   
                        //PrimaryExpression[
                        (
                        (PrimarySuffix[
                                ends-with(@Image,'getDeclaredConstructors')
                                        or
                                ends-with(@Image,'getDeclaredConstructor')
                                        or
                                ends-with(@Image,'setAccessible')
                                ])
                        or
                        (PrimaryPrefix/Name[
                                ends-with(@Image,'getDeclaredConstructor')
                                or
                                ends-with(@Image,'getDeclaredConstructors')
                                or
                                starts-with(@Image,'AccessibleObject.setAccessible')
                                ])
                        )
                        and
                        (//ImportDeclaration/Name[
                                contains(@Image,'java.security.PrivilegedAction')])
                ]
                
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.UnusedPrivateFieldRule" message="Avoid unused private fields such as ''{0}''." name="UnusedPrivateField">
        <description>
Detects when a private field is declared and/or assigned a value, but not used.
    </description>
        <example><![CDATA[

public class Something {
  private static int FOO = 2; // Unused
  private int i = 5; // Unused
  private int j = 6;
  public int addOne() {
    return j++;
  }
}

    ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.UnusedLocalVariableRule" message="Avoid unused local variables such as ''{0}''." name="UnusedLocalVariable">
        <description>
Detects when a local variable is declared and/or assigned, but not used.
    </description>
        <example><![CDATA[

public class Foo {
 public void doSomething() {
  int i = 5; // Unused
 }
}

    ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.UnusedPrivateMethodRule" message="Avoid unused private methods such as ''{0}''." name="UnusedPrivateMethod">
        <description>
Unused Private Method detects when a private method is declared but is unused.
    </description>
        <example><![CDATA[

public class Something {
 private void foo() {} // unused
}

    ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.UnusedFormalParameterRule" message="Avoid unused {0} parameters such as ''{1}''." name="UnusedFormalParameter">
        <description>
Avoid passing parameters to methods or constructors and then not using those parameters.
    </description>
        <example><![CDATA[

public class Foo {
 private void bar(String howdy) {
  // howdy is not used
 }

    ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.typeresolution.rules.LooseCoupling" message="Avoid using implementation types like ''{0}''; use the interface instead" name="LooseCoupling">
        <description>
Avoid using implementation types (i.e., HashSet); use the interface (i.e, Set) instead
      </description>
        <example><![CDATA[

import java.util.ArrayList;
import java.util.HashSet;
public class Bar {
 // Use List instead
 private ArrayList list = new ArrayList();
 // Use Set instead
 public HashSet getFoo() {
  return new HashSet();
 }
}
  
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.typeresolution.rules.CloneMethodMustImplementCloneable" message="clone() method should be implemented only if implementing Cloneable interface" name="CloneMethodMustImplementCloneable">
        <description>
The method clone() should only be implemented if the class implements the 
Cloneable interface with the exception of a final method that only throws 
CloneNotSupportedException. This version uses PMD's type resolution facilities, 
and can detect if the class implements or extends a Cloneable class
        </description>
        <example><![CDATA[
            
public class MyClass {
 public Object clone() throws CloneNotSupportedException {
  return foo;
 }
}
   
        ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.typeresolution.rules.imports.UnusedImports" message="Avoid unused imports such as ''{0}''" name="UnusedImports">
        <description>
    Avoid unused import statements. This rule will find unused on demand imports, i.e. import com.foo.*.
    </description>
        <example><![CDATA[

// this is bad
import java.io.*;
public class Foo {}

    ]]></example>
        <priority>4</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.typeresolution.rules.SignatureDeclareThrowsException" message="A method/constructor shouldn't explicitly throw java.lang.Exception" name="SignatureDeclareThrowsException">
        <description>
It is unclear which exceptions that can be thrown from the methods.
It might be difficult to document and understand the vague interfaces.
Use either a class derived from RuntimeException or a checked exception.

Junit classes are excluded.
      </description>
        <example><![CDATA[
      	
public void methodThrowingException() throws Exception {
}
      	
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="IgnoreJUnitCompletely" value="false"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.BeanMembersShouldSerializeRule" message="Found non-transient, non-static member. Please mark as transient or provide accessors." name="BeanMembersShouldSerialize">
        <description>If a class is a bean, or is referenced by a bean directly or indirectly
it needs to be serializable. Member variables need to be marked as transient,
static, or have accessor methods in the class. Marking variables
as transient is the safest and easiest modification. Accessor methods should
follow the Java naming conventions, i.e.if you have a variable foo, you should
provide getFoo and setFoo methods.</description>
        <example><![CDATA[private transient int someFoo;//good, it's transient
  private static int otherFoo;// also OK
  private int moreFoo;// OK, has proper accessors, see below
  private int badFoo;//bad, should be marked transient


  private void setMoreFoo(int moreFoo){
        this.moreFoo = moreFoo;
  }

  private int getMoreFoo(){
        return this.moreFoo;
  }]]></example>
        <priority>5</priority>
        <properties>
            <property name="prefix" value=""/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Classes implementing Serializable should set a serialVersionUID" name="MissingSerialVersionUID">
        <description>
Classes that are serializable should provide a serialVersionUID field.
      </description>
        <example><![CDATA[

public class Foo implements java.io.Serializable {
 String name;
 // Define serialization id to avoid serialization related bugs
 // i.e., public static final long serialVersionUID = 4328743;
}


          ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//ClassOrInterfaceDeclaration
 [
  count(ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration
   /FieldDeclaration/VariableDeclarator/VariableDeclaratorId[@Image='serialVersionUID']) = 0
and
  count(ImplementsList
   [ClassOrInterfaceType/@Image='Serializable'
   or ClassOrInterfaceType/@Image='java.io.Serializable']) =1
and
   @Abstract = 'false'
]

              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.strictexception.AvoidCatchingThrowable" message="A catch statement should never catch throwable since it includes errors." name="AvoidCatchingThrowable">
        <description>
This is dangerous because it casts too wide a net; it can catch things like OutOfMemoryError.
      </description>
        <example><![CDATA[
                
public class Foo {
 public void bar() {
  try {
   // do something
  } catch (Throwable th) {  //Should not catch throwable
   th.printStackTrace();
  }
 }
}
                
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.strictexception.ExceptionSignatureDeclaration" message="A method/constructor shouldn't explicitly throw java.lang.Exception" name="SignatureDeclareThrowsException">
        <description>
It is unclear which exceptions that can be thrown from the methods.
It might be difficult to document and understand the vague interfaces.
Use either a class derived from RuntimeException or a checked exception.
      </description>
        <example><![CDATA[
                
public void methodThrowingException() throws Exception {
}
                
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.ExceptionAsFlowControl" message="Avoid using exceptions as flow control." name="ExceptionAsFlowControl">
        <description>
          Using Exceptions as flow control leads to GOTOish code and obscures true exceptions when debugging.
      </description>
        <example><![CDATA[
  
public class Foo {
 void bar() {
  try {
   try {
   } catch (Exception e) {
    throw new WrapperException(e);
    // this is essentially a GOTO to the WrapperException catch block
   }
  } catch (WrapperException e) {
   // do some more stuff
  }
 }
}
  
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid catching NullPointerException; consider removing the cause of the NPE." name="AvoidCatchingNPE">
        <description>
      Code should never throw NPE under normal circumstances.  A catch block may hide the original error, causing other more subtle errors in its wake.
    </description>
        <example><![CDATA[  
public class Foo {
 void bar() {
  try {
   // do something
   }  catch (NullPointerException npe) {
  }
 }
}

    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
            
//CatchStatement/FormalParameter/Type
 /ReferenceType/ClassOrInterfaceType[@Image='NullPointerException']
 
        ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid throwing raw exception types." name="AvoidThrowingRawExceptionTypes">
        <description>
Avoid throwing certain exception types. Rather than throw a raw RuntimeException, Throwable,
Exception, or Error, use a subclassed exception or error instead.
    </description>
        <example><![CDATA[
      
public class Foo {
public void bar() throws Exception {
  throw new Exception();
 }
}

    ]]></example>
        <priority>1</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
            
//AllocationExpression
 /ClassOrInterfaceType[
 (@Image='Throwable' and count(//ImportDeclaration/Name[ends-with(@Image,'Throwable')]) = 0)
or
 (@Image='Exception' and count(//ImportDeclaration/Name[ends-with(@Image,'Exception')]) = 0)
or
 (@Image='Error'  and count(//ImportDeclaration/Name[ends-with(@Image,'Error')]) = 0)
or
( @Image='RuntimeException'  and count(//ImportDeclaration/Name[ends-with(@Image,'RuntimeException')]) = 0)
]
 
        ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid throwing null pointer exceptions." name="AvoidThrowingNullPointerException">
        <description>
Avoid throwing a NullPointerException - it's confusing because most people will assume that the
virtual machine threw it. Consider using an IllegalArgumentException instead; this will be
clearly seen as a programmer-initiated exception.
      </description>
        <example><![CDATA[
        
public class Foo {
 void bar() {
  throw new NullPointerException();
 }
}
  
      ]]></example>
        <priority>1</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
              
//AllocationExpression/ClassOrInterfaceType[@Image='NullPointerException']
   
          ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="A catch statement that catches an exception only to rethrow it should be avoided." name="AvoidRethrowingException">
        <description>
     Catch blocks that merely rethrow a caught exception only add to code size and runtime complexity.
    </description>
        <example><![CDATA[  
  public class Foo {
   void bar() {
    try {
    // do something
    }  catch (SomeException se) {
       throw se;
    }
   }
  }
  
    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                
//CatchStatement[FormalParameter
 /VariableDeclaratorId/@Image = Block/BlockStatement/Statement
 /ThrowStatement/Expression/PrimaryExpression[count(PrimarySuffix)=0]/PrimaryPrefix/Name/@Image
 and count(Block/BlockStatement/Statement) =1]
 
            ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Exceptions should not extend java.lang.Error" name="DoNotExtendJavaLangError">
        <description>
      [
        Errors are system exceptions. Do not extend them.
      
    </description>
        <example><![CDATA[
        public class Foo extends Error { }
    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
          
//ClassOrInterfaceDeclaration/ExtendsList/ClassOrInterfaceType
  [@Image="Error" or @Image="java.lang.Error"]
          
        ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid empty catch blocks" name="EmptyCatchBlock">
        <description>
Empty Catch Block finds instances where an exception is caught,
but nothing is done.  In most circumstances, this swallows an exception
which should either be acted on or reported.
      </description>
        <example><![CDATA[
  
public void doSomething() {
  try {
    FileInputStream fis = new FileInputStream("/tmp/bugger");
  } catch (IOException ioe) {
      // not good
  }
}
 
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//CatchStatement
 [count(Block/BlockStatement) = 0 and ($allowCommentedBlocks != 'true' or Block/@containsComment = 'false')]
 [FormalParameter/Type/ReferenceType
   /ClassOrInterfaceType[@Image != 'InterruptedException' and @Image != 'CloneNotSupportedException']
 ]
 
             ]]></value>
            </property>
            <property name="allowCommentedBlocks" value="false"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid empty 'if' statements" name="EmptyIfStmt">
        <description>
Empty If Statement finds instances where a condition is checked but nothing is done about it.
    </description>
        <example><![CDATA[
    
public class Foo {
 void bar(int x) {
  if (x == 0) {
   // empty!
  }
 }
}
 
       ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//IfStatement/Statement
 [EmptyStatement or Block[count(*) = 0]]
 
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid empty 'while' statements" name="EmptyWhileStmt">
        <description>
Empty While Statement finds all instances where a while statement
does nothing.  If it is a timing loop, then you should use Thread.sleep() for it; if
it's a while loop that does a lot in the exit expression, rewrite it to make it clearer.
       </description>
        <example><![CDATA[
  
public class Foo {
 void bar(int a, int b) {
  while (a == b) {
   // empty!
  }
 }
}
 
       ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//WhileStatement/Statement[./Block[count(*) = 0]  or ./EmptyStatement]

              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid empty try blocks" name="EmptyTryBlock">
        <description>
Avoid empty try blocks - what's the point?
      </description>
        <example><![CDATA[
  
public class Foo {
 public void bar() {
  try {
  } catch (Exception e) {
    e.printStackTrace();
  }
 }
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//TryStatement/Block[1][count(*) = 0]

              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid empty finally blocks" name="EmptyFinallyBlock">
        <description>
Avoid empty finally blocks - these can be deleted.
      </description>
        <example><![CDATA[
  
public class Foo {
 public void bar() {
  try {
    int x=2;
   } finally {
    // empty!
   }
 }
}
 
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//FinallyStatement[count(Block/BlockStatement) = 0]
 
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid empty switch statements" name="EmptySwitchStatements">
        <description>
Avoid empty switch statements.
      </description>
        <example><![CDATA[
  
public class Foo {
 public void bar() {
  int x = 2;
  switch (x) {
   // once there was code here
   // but it's been commented out or something
  }
 }
}
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//SwitchStatement[count(*) = 1]
 
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid modifying an outer loop incrementer in an inner loop for update expression" name="JumbledIncrementer">
        <description>
Avoid jumbled loop incrementers - it's usually a mistake, and it's confusing even if it's what's intended.
     </description>
        <example><![CDATA[
 
public class JumbledIncrementerRule1 {
  public void foo() {
   for (int i = 0; i < 10; i++) {
    for (int k = 0; k < 20; i++) {
     System.out.println("Hello");
    }
   }
  }
 }
 
     ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
 
//ForStatement
 [
  ForUpdate/StatementExpressionList/StatementExpression/PostfixExpression/PrimaryExpression/PrimaryPrefix/Name/@Image
  =
  ancestor::ForStatement/ForInit//VariableDeclaratorId/@Image
 ]
 
             ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="This for loop could be simplified to a while loop" name="ForLoopShouldBeWhileLoop">
        <description>
Some for loops can be simplified to while loops - this makes them more concise.
      </description>
        <example><![CDATA[
  
public class Foo {
 void bar() {
  for (;true;) true; // No Init or Update part, may as well be: while (true)
 }
}
 
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                
//ForStatement
 [count(*) > 1]
 [not(ForInit)]
 [not(ForUpdate)]
 [not(Type and Expression and Statement)]
 
            ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.UnnecessaryConversionTemporary" message="Avoid unnecessary temporaries when converting primitives to Strings" name="UnnecessaryConversionTemporary">
        <description>
Avoid unnecessary temporaries when converting primitives to Strings
      </description>
        <example><![CDATA[
  
public String convert(int x) {
  // this wastes an object
  String foo = new Integer(x).toString();
  // this is better
  return Integer.toString(x);
}
 
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.OverrideBothEqualsAndHashcode" message="Ensure you override both equals() and hashCode()" name="OverrideBothEqualsAndHashcode">
        <description>
Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or override neither.  Even if you are inheriting a hashCode() from a parent class, consider implementing hashCode and explicitly delegating to your superclass.
      </description>
        <example><![CDATA[
  
// this is bad
public class Bar {
  public boolean equals(Object o) {
      // do some comparison
  }
}

// and so is this
public class Baz {
  public int hashCode() {
      // return some hash value
  }
}

// this is OK
public class Foo {
  public boolean equals(Object other) {
      // do some comparison
  }
  public int hashCode() {
      // return some hash value
  }
}
 
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.DoubleCheckedLocking" message="Double checked locking is not thread safe in Java." name="DoubleCheckedLocking">
        <description>
Partially created objects can be returned by the Double Checked Locking pattern when used in Java.
An optimizing JRE may assign a reference to the baz variable before it creates the object the
  reference is intended to point to.  For more details see http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html.
      </description>
        <example><![CDATA[
  
public class Foo {
  Object baz;
  Object bar() {
    if(baz == null) { //baz may be non-null yet not fully created
      synchronized(this){
        if(baz == null){
          baz = new Object();
        }
      }
    }
    return baz;
  }
}
 
      ]]></example>
        <priority>1</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid returning from a finally block" name="ReturnFromFinallyBlock">
        <description>
Avoid returning from a finally block - this can discard exceptions.
      </description>
        <example><![CDATA[
  
public class Bar {
 public String foo() {
  try {
   throw new Exception( "My Exception" );
  } catch (Exception e) {
   throw e;
  } finally {
   return "A. O. K."; // Very bad.
  }
 }
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//FinallyStatement//ReturnStatement

              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid empty synchronized blocks" name="EmptySynchronizedBlock">
        <description>
  Avoid empty synchronized blocks - they're useless.
      </description>
        <example><![CDATA[

public class Foo {
 public void bar() {
  synchronized (this) {
   // empty!
  }
 }
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//SynchronizedStatement/Block[1][count(*) = 0]

              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.basic.UnnecessaryReturn" message="Avoid unnecessary return statements" name="UnnecessaryReturn">
        <description>
Avoid unnecessary return statements
      </description>
        <example><![CDATA[
  
public class Foo {
 public void bar() {
  int x = 42;
  return;
 }
}
 
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Empty static initializer was found" name="EmptyStaticInitializer">
        <description>
An empty static initializer was found.
       </description>
        <example><![CDATA[
   
public class Foo {
 static {
  // empty
 }
 }

       ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//Initializer[@Static='true']/Block[count(*)=0]

                 ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Do not use 'if' statements that are always true or always false" name="UnconditionalIfStatement">
        <description>
Do not use "if" statements that are always true or always false.
      </description>
        <example><![CDATA[
  
public class Foo {
 public void close() {
  if (true) {
       // ...
   }
 }
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
 
//IfStatement/Expression
 [count(PrimaryExpression)=1]
 /PrimaryExpression/PrimaryPrefix/Literal/BooleanLiteral

                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="An empty statement (semicolon) not part of a loop" name="EmptyStatementNotInLoop">
        <description>
An empty statement (aka a semicolon by itself) that is not used
as the sole body of a for loop or while loop is probably a bug.  It
could also be a double semicolon, which is useless and should be
removed.
       </description>
        <example><![CDATA[

public class MyClass {
   public void doit() {
      // this is probably not what you meant to do
      ;
      // the extra semicolon here this is not necessary
      System.out.println("look at the extra semicolon");;
   }
}

       ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//EmptyStatement
 [not(
       ../../../ForStatement
       or ../../../WhileStatement
       or ../../../BlockStatement/ClassOrInterfaceDeclaration
       or ../../../../../../ForStatement/Statement[1]
        /Block[1]/BlockStatement[1]/Statement/EmptyStatement
       or ../../../../../../WhileStatement/Statement[1]
        /Block[1]/BlockStatement[1]/Statement/EmptyStatement)
 ]

                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.basic.BooleanInstantiation" message="Avoid instantiating Boolean objects; reference Boolean.TRUE or Boolean.FALSE or call Boolean.valueOf() instead." name="BooleanInstantiation">
        <description>
Avoid instantiating Boolean objects; you can reference Boolean.TRUE, Boolean.FALSE, or call Boolean.valueOf() instead.
   </description>
        <example><![CDATA[
   
public class Foo {
 Boolean bar = new Boolean("true"); // just do a Boolean bar = Boolean.TRUE;
 Boolean buz = Boolean.valueOf(false); // just do a Boolean buz = Boolean.FALSE;
}
   
   ]]></example>
        <priority>2</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Unnecessary final modifier in final class" name="UnnecessaryFinalModifier">
        <description>
When a class has the final modifier, all the methods are automatically final.
      </description>
        <example><![CDATA[

public final class Foo {
    // This final modifier is not necessary, since the class is final
    // and thus, all methods are final
    private final void foo() {
    }
}


      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//ClassOrInterfaceDeclaration[@Final='true' and @Interface='false']
/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/MethodDeclaration[@Final='true']
    
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="These nested if statements could be combined" name="CollapsibleIfStatements">
        <description>
Sometimes two 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator.
      </description>
        <example><![CDATA[
  
public class Foo {
 void bar() {
  if (x) {
   if (y) {
    // do stuff
   }
  }
 }
}
 
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                
//IfStatement[@Else='false']/Statement
 /IfStatement[@Else='false']
 |
//IfStatement[@Else='false']/Statement
 /Block[count(BlockStatement)=1]/BlockStatement
  /Statement/IfStatement[@Else='false']
            ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.UselessOverridingMethod" message="Overriding method merely calls super" name="UselessOverridingMethod">
        <description>
The overriding method merely calls the same method defined in a superclass
        </description>
        <example><![CDATA[
public void foo(String bar) {
    super.foo(bar);      //Why bother overriding?
}
        ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="This usage of the Collection.toArray() method will throw a ClassCastException." name="ClassCastExceptionWithToArray">
        <description>
if you need to get an array of a class from your Collection,
you should pass an array of the desidered class
as the parameter of the toArray method. Otherwise you will get a
ClassCastException.
  </description>
        <example><![CDATA[

import java.util.ArrayList;
import java.util.Collection;

public class Test {

    public static void main(String[] args) {
        Collection c=new ArrayList();
        Integer obj=new Integer(1);
        c.add(obj);

        // this would trigger the rule (and throw a ClassCastException
if executed)
        Integer[] a=(Integer [])c.toArray();

        // this wouldn't trigger the rule
        Integer[] b=(Integer [])c.toArray(new Integer[c.size()]);
    }
}

  ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//CastExpression[Type/ReferenceType/ClassOrInterfaceType[@Image !=
"Object"]]//PrimaryExpression
[
 PrimaryPrefix/Name[ends-with(@Image, '.toArray')]
 and
 PrimarySuffix/Arguments[count(*) = 0]
and
count(PrimarySuffix) = 1
]

    ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid creating BigDecimal with a decimal (float/double) literal. Use a String literal" name="AvoidDecimalLiteralsInBigDecimalConstructor">
        <description>
     One might assume that "new BigDecimal(.1)" is exactly equal
     to .1, but it is actually equal
     to .1000000000000000055511151231257827021181583404541015625.
     This is so because .1 cannot be represented exactly as a double
     (or, for that matter, as a binary fraction of any finite length).
     Thus, the long value that is being passed in to the constructor
     is not exactly equal to .1, appearances notwithstanding.

     The (String) constructor, on the other hand, is perfectly predictable:
     'new BigDecimal(".1")' is exactly equal to .1, as one
     would expect.  Therefore, it is generally recommended that the (String)
     constructor be used in preference to this one.
  </description>
        <example><![CDATA[

import java.math.BigDecimal;
public class Test {

    public static void main(String[] args) {
      // this would trigger the rule
     BigDecimal bd=new BigDecimal(1.123);
      // this wouldn't trigger the rule
     BigDecimal bd=new BigDecimal("1.123");
      // this wouldn't trigger the rule
     BigDecimal bd=new BigDecimal(12);
    }
}

  ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//AllocationExpression[ClassOrInterfaceType[@Image="BigDecimal"]
and
./Arguments/ArgumentList
/Expression/PrimaryExpression/PrimaryPrefix/Literal[(not
(ends-with
(@Image,'"'))) and contains(@Image,".")]]
 
    ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.UselessOperationOnImmutable" message="An operation on an Immutable object (BigDecimal or BigInteger) won't change the object itself" name="UselessOperationOnImmutable">
        <description>
    An operation on an Immutable object (BigDecimal or BigInteger) won't change the object itself. The
    result of the operation is a new object. Therefore, ignoring the operation result is an error.
      </description>
        <example><![CDATA[
    
import java.math.*;
class Test {
 void method1() {
  BigDecimal bd=new BigDecimal(10);
  bd.add(new BigDecimal(5)); // this will trigger the rule
 }
 void method2() {
  BigDecimal bd=new BigDecimal(10);
  bd = bd.add(new BigDecimal(5)); // this won't trigger the rule
 }
}
    
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="The null check here is misplaced; if the variable is null there'll be a NullPointerException" name="MisplacedNullCheck">
        <description>
    The null check here is misplaced. if the variable is null you'll get a NullPointerException.
    Either the check is useless (the variable will never be "null") or it's incorrect.
      </description>
        <example><![CDATA[
    
public class Foo {
 void bar() {
  if (a.equals(baz) && a != null) {}
 }
}
    
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//Expression
    /*[self::ConditionalOrExpression or self::ConditionalAndExpression]
     /descendant::PrimaryExpression/PrimaryPrefix
      /Name[starts-with(@Image,
      concat(ancestor::PrimaryExpression/following-sibling::EqualityExpression
       [./PrimaryExpression/PrimaryPrefix/Literal/NullLiteral]
     /PrimaryExpression/PrimaryPrefix
      /Name[count(../../PrimarySuffix)=0]/@Image,"."))
    ]
    
        ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Invoke equals() on the object you''ve already ensured is not null" name="UnusedNullCheckInEquals">
        <description>
    After checking an object reference for null, you should invoke equals() on that object rather than passing it to another object's equals() method.
    </description>
        <example><![CDATA[

public class Test {

public String method1() { return "ok";}
public String method2() { return null;}

public void method(String a) {
String b;
/*
I don't know it method1() can be "null"
but I know "a" is not null..
I'd better write a.equals(method1())
*/
if (a!=null && method1().equals(a)) { // will
trigger the rule
//whatever
}

if (method1().equals(a) && a != null) { //
won't trigger the rule
//whatever
}

if (a!=null && method1().equals(b)) { // won't
trigger the rule
//whatever
}

if (a!=null && "LITERAL".equals(a)) { // won't
trigger the rule
//whatever
}

if (a!=null && !a.equals("go")) { // won't
trigger the rule
a=method2();
if (method1().equals(a)) {
//whatever
}
}
}
}

]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
        
//PrimarySuffix[@Image='equals' and not(../PrimaryPrefix/Literal)]
 /../PrimarySuffix/Arguments/ArgumentList/Expression
 /PrimaryExpression/PrimaryPrefix
 /Name[@Image = ./../../../../../../../../../../Expression/ConditionalAndExpression
 /EqualityExpression[@Image="!=" and count(./preceding-sibling::*)=0 and
 ./PrimaryExpression/PrimaryPrefix/Literal/NullLiteral]
  /PrimaryExpression/PrimaryPrefix/Name/@Image]
        
        ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid using ThreadGroup; it is not thread safe" name="AvoidThreadGroup">
        <description>
Avoid using ThreadGroup; although it is intended to be used in a threaded environment
 it contains methods that are not thread safe.
      </description>
        <example><![CDATA[
    
    public class Bar {
     void buz() {
      ThreadGroup tg = new ThreadGroup("My threadgroup") ;
      tg = new ThreadGroup(tg, "my thread group");
      tg = Thread.currentThread().getThreadGroup();
      tg = System.getSecurityManager().getThreadGroup();
     }
    }
    
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//AllocationExpression/ClassOrInterfaceType[contains(@Image,'ThreadGroup')] |
//PrimarySuffix[contains(@Image, 'getThreadGroup')]

        ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.basic.BrokenNullCheck" message="Method call on object which may be null" name="BrokenNullCheck">
        <description>
The null check is broken since it will throw a NullPointerException itself.
It is likely that you used || instead of &amp;&amp; or vice versa.
     </description>
        <example><![CDATA[

class Foo {
 String bar(String string) {
  // should be &&
  if (string!=null || !string.equals(""))
    return string;
  // should be ||
  if (string==null && string.equals(""))
    return string;
 }
}
        
        ]]></example>
        <priority>2</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.basic.BigIntegerInstantiation" message="Don't create instances of already existing BigInteger and BigDecimal (ZERO, ONE, TEN)" name="BigIntegerInstantiation">
        <description>
Don't create instances of already existing BigInteger
(BigInteger.ZERO, BigInteger.ONE) and for 1.5 on,
BigInteger.TEN and BigDecimal (BigDecimal.ZERO,
BigDecimal.ONE, BigDecimal.TEN)
  </description>
        <example><![CDATA[

public class Test {

 public static void main(String[] args) {
   BigInteger bi=new BigInteger(1);
   BigInteger bi2=new BigInteger("0");
   BigInteger bi3=new BigInteger(0.0);
   BigInteger bi4;
   bi4=new BigInteger(0);
 }
}

  ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.basic.AvoidUsingOctalValues" message="Do not start a literal by 0 unless it's an octal value" name="AvoidUsingOctalValues">
        <description>
    	
		    Integer literals should not start with zero.
		    Zero means that the rest of literal will be interpreted as an octal value.
    	
    </description>
        <example><![CDATA[
		    
		public class Foo {
		  int i = 012; // set i with 10 not 12
		  int j = 010; // set j with 8 not 10
		  k = i * j; // set k with 80 not 120
		}
		    
    ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.basic.AvoidUsingHardCodedIP" message="Do not hard code IPv4 or IPv6 addresses, even 127.0.0.1 !" name="AvoidUsingHardCodedIP">
        <description>
	    	
				An application with hard coded IP may become impossible to deploy in some case. It never hurts
				to externalize IP adresses.
	    	
	    </description>
        <example><![CDATA[
	    
	public class Foo {
	  String ip = "127.0.0.1"; // This is a really bad idea !
	}
	    
	    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="pattern" value="^&quot;[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}&quot;$"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Always check the return of one of the navigation method (next,previous,first,last) of a ResultSet." name="CheckResultSet">
        <description>
            
	            Always check the return of one of the navigation method (next,previous,first,last) of a ResultSet. Indeed,
	            if the value return is 'false', the developer should deal with it !
            
        </description>
        <example><![CDATA[
            [
            // This is NOT appropriate !
            Statement stat = conn.createStatement();
            ResultSet rst = stat.executeQuery("SELECT name FROM person");
            rst.next(); // what if it returns a 'false' ?
            String firstName = rst.getString(1);

            // This is appropriate...
            Statement stat = conn.createStatement();
            ResultSet rst = stat.executeQuery("SELECT name FROM person");
            if (rst.next())
            {
                String firstName = rst.getString(1);
            }
            else
            {
                // here you deal with the error ( at least log it)
            }
            
        ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
		        	
//Type/ReferenceType/ClassOrInterfaceType[
	(@Image = 'ResultSet')
	and
	(../../../descendant::Name[ends-with(@Image,'executeQuery')])
	and
	(
		not (contains(
			(./ancestor::Block/descendant::IfStatement/descendant::Name/attribute::Image),
			(concat(../../../VariableDeclarator/VariableDeclaratorId/attribute::Image,'.next') )
		))
		and
		not (contains(
			(./ancestor::Block/descendant::IfStatement/descendant::Name/attribute::Image),
			(concat(../../../VariableDeclarator/VariableDeclaratorId/attribute::Image,'.previous') )
		) )
		and
		not (contains(
			(./ancestor::Block/descendant::IfStatement/descendant::Name/attribute::Image),
			(concat(../../../VariableDeclarator/VariableDeclaratorId/attribute::Image,'.first') )
		) )
		and
		not (contains(
			(./ancestor::Block/descendant::IfStatement/descendant::Name/attribute::Image),
			(concat(../../../VariableDeclarator/VariableDeclaratorId/attribute::Image,'.last') )
		) )
	)
]
		        	
            	]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid using if statements without curly braces" name="IfStmtsMustUseBraces">
        <description>
Avoid using if statements without using curly braces.
     </description>
        <example><![CDATA[
 
 public class Foo {
   public void bar() {
     int x = 0;
     if (foo) x++;
   }
 }
 
     ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                   
//IfStatement[count(*) < 3][not(Statement/Block)]
                   
               ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid using 'while' statements without curly braces" name="WhileLoopsMustUseBraces">
        <description>
Avoid using 'while' statements without using curly braces.
      </description>
        <example><![CDATA[

public void doSomething() {
  while (true)
      x++;
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//WhileStatement[not(Statement/Block)]

                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid using 'if...else' statements without curly braces" name="IfElseStmtsMustUseBraces">
        <description>
Avoid using if..else statements without using curly braces.
       </description>
        <example><![CDATA[

 public void doSomething() {
   // this is OK
   if (foo) x++;
   // but this is not
   if (foo)
       x=x+1;
   else
       x=x-1;
 }

       ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//Statement
 [parent::IfStatement[@Else='true']]
 [not(child::Block)]
 [not(child::IfStatement)]
 
                 ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid using 'for' statements without curly braces" name="ForLoopsMustUseBraces">
        <description>
Avoid using 'for' statements without using curly braces.
       </description>
        <example><![CDATA[

public void foo() {
 for (int i=0; i<42;i++)
   foo();
}

       ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
 
//ForStatement[not(Statement/Block)]
 
                 ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid empty finalize methods" name="EmptyFinalizer">
        <description>
If the finalize() method is empty, then it does not need to exist.
       </description>
        <example><![CDATA[

public class Foo {
   protected void finalize() {}
}

       ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//MethodDeclaration[MethodDeclarator[@Image='finalize'][not(FormalParameters/*)]]
  /Block[count(*)=0]

                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Finalize should do something besides just calling super.finalize()" name="FinalizeOnlyCallsSuperFinalize">
        <description>
If the finalize() is implemented, it should do something besides just calling
super.finalize().
       </description>
        <example><![CDATA[
           
public class Foo {
   protected void finalize() {
     super.finalize();
   }
}
           
       ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//MethodDeclaration[MethodDeclarator[@Image="finalize"][not(FormalParameters/*)]]
   /Block[count(BlockStatement)=1]
     /BlockStatement[
       Statement/StatementExpression/PrimaryExpression
      /PrimaryPrefix[@Image="finalize"]
      ]

                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Finalize methods should not be overloaded" name="FinalizeOverloaded">
        <description>
Methods named finalize() should not have parameters.  It is
confusing and probably a bug to overload finalize().  It will
not be called by the VM.
   </description>
        <example><![CDATA[

public class Foo {
   // this is confusing and probably a bug
   protected void finalize(int a) {
   }
}

   ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//MethodDeclaration
 /MethodDeclarator[@Image='finalize'][FormalParameters[count(*)>0]]

            ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Last statement in finalize method should be a call to super.finalize()" name="FinalizeDoesNotCallSuperFinalize">
        <description>
If the finalize() is implemented, its last action should be to call super.finalize.
       </description>
        <example><![CDATA[

public class Foo {
   protected void finalize() {
       something();
       // neglected to call super.finalize()
   }
}

       ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[


//MethodDeclaration[MethodDeclarator[@Image='finalize'][not(FormalParameters/*)]]
   /Block
      /BlockStatement[last()]
      [not(Statement/StatementExpression/PrimaryExpression/PrimaryPrefix[@Image='finalize'])]
      [not(Statement/TryStatement/FinallyStatement
       /Block/BlockStatement/Statement/StatementExpression
        /PrimaryExpression/PrimaryPrefix[@Image='finalize'])]

                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="If you override finalize(), make it protected" name="FinalizeShouldBeProtected">
        <description>
If you override finalize(), make it protected.  If you make
 it public, other classes may call it.
      </description>
        <example><![CDATA[
  
public class Foo {
 public void finalize() {
  // do something
 }
}
  
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                    
//MethodDeclaration[@Protected="false"]
  /MethodDeclarator[@Image="finalize"]
  [not(FormalParameters/*)]
                    
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.AvoidCallingFinalize" message="Avoid calling finalize() explicitly" name="AvoidCallingFinalize">
        <description>
Object.finalize() is called by the garbage collector on an object when garbage collection determines
that there are no more references to the object.
      </description>
        <example><![CDATA[

public class Foo {
 void foo() {
  Bar b = new Bar();
  b.finalize();
 }
}

      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.MoreThanOneLogger" message="Class contains more than one logger." name="MoreThanOneLogger">
        <description>
Normally only one logger is used in each class.
     </description>
        <example><![CDATA[
 
class Foo{
    Logger log = Logger.getLogger(Foo.class.getName());
    // It is very rare to see two loggers on a class, normally
    // log information is multiplexed by levels
    Logger log2= Logger.getLogger(Foo.class.getName());
}

     ]]></example>
        <priority>2</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="The Logger variable declaration does not contain the static and final modifiers" name="LoggerIsNotStaticFinal">
        <description>
In most cases, the Logger can be declared static and final.
     </description>
        <example><![CDATA[
 
class Foo{
    Logger log = Logger.getLogger(Foo.class.getName());
    // It is much better to declare the logger as follows 
    // static final Logger log = Logger.getLogger(Foo.class.getName());
}

     ]]></example>
        <priority>2</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                 
//VariableDeclarator
 [parent::FieldDeclaration]
 [../Type/ReferenceType
  /ClassOrInterfaceType[@Image='Logger']
   and
  (..[@Final='false'] or ..[@Static = 'false'] ) ]
                
             ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="System.out.print is used" name="SystemPrintln">
        <description>
System.(out|err).print is used, consider using a logger.
     </description>
        <example><![CDATA[
 
class Foo{
    Logger log = Logger.getLogger(Foo.class.getName());
    public void testA () {
        System.out.println("Entering test");
        // Better use this
        log.fine("Entering test");
    }
}

     ]]></example>
        <priority>2</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                 
//Name[
    starts-with(@Image, 'System.out.print')
    or
    starts-with(@Image, 'System.err.print')
    ]
                
             ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid printStackTrace(); use a logger call instead." name="AvoidPrintStackTrace">
        <description>
Avoid printStackTrace(); use a logger call instead.
           </description>
        <example><![CDATA[

class Foo {
 void bar() {
  try {
   // do something
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}

           ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//PrimaryExpression
 [PrimaryPrefix/Name[contains(@Image,'printStackTrace')]]
 [PrimarySuffix[not(boolean(Arguments/ArgumentList/Expression))]]

             ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.strings.AvoidDuplicateLiteralsRule" message="The String literal {0} appears {1} times in this file; the first occurrence is on line {2}" name="AvoidDuplicateLiterals">
        <description>
Code containing duplicate String literals can usually be improved by declaring the String as a constant field.
    </description>
        <example><![CDATA[

public class Foo {
 private void bar() {
    buz("Howdy");
    buz("Howdy");
    buz("Howdy");
    buz("Howdy");
 }
 private void buz(String x) {}
}

    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="threshold" value="4"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.strings.StringInstantiation" message="Avoid instantiating String objects; this is usually unnecessary." name="StringInstantiation">
        <description>
Avoid instantiating String objects; this is usually unnecessary.
    </description>
        <example><![CDATA[

public class Foo {
 private String bar = new String("bar"); // just do a String bar = "bar";
}

    ]]></example>
        <priority>2</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.strings.StringToStringRule" message="Avoid calling toString() on String objects; this is unnecessary." name="StringToString">
        <description>
    Avoid calling toString() on String objects; this is unnecessary.
    </description>
        <example><![CDATA[

public class Foo {
 private String baz() {
  String bar = "howdy";
  return bar.toString();
 }
}

    ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.strings.InefficientStringBuffering" message="Avoid concatenating nonliterals in a StringBuffer constructor or append()." name="InefficientStringBuffering">
        <description>
Avoid concatenating non literals in a StringBuffer constructor or append().
    </description>
        <example><![CDATA[

public class Foo {
 void bar() {
  // Avoid this
  StringBuffer sb=new StringBuffer("tmp = "+System.getProperty("java.io.tmpdir"));
  // use instead something like this
  StringBuffer sb = new StringBuffer("tmp = ");
  sb.append(System.getProperty("java.io.tmpdir"));
 }
}

    ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.strings.UnnecessaryCaseChange" message="Using equalsIgnoreCase() is cleaner than using toUpperCase/toLowerCase().equals()." name="UnnecessaryCaseChange">
        <description>
Using equalsIgnoreCase() is faster than using toUpperCase/toLowerCase().equals()
       </description>
        <example><![CDATA[
                 
 public class Foo {
  public boolean bar(String buz) {
    // should be buz.equalsIgnoreCase("baz")
    return buz.toUpperCase().equals("baz");
    // another unnecessary toUpperCase()
    // return buz.toUpperCase().equalsIgnoreCase("baz");
  }
 }
                 
       ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.strings.UseStringBufferLength" message="This is an inefficient use of StringBuffer.toString; call StringBuffer.length instead." name="UseStringBufferLength">
        <description>
 Use StringBuffer.length() to determine StringBuffer length rather than using StringBuffer.toString().equals("")
          or StringBuffer.toString().length() ==.
      </description>
        <example><![CDATA[
  
public class Foo {
 void bar() {
  StringBuffer sb = new StringBuffer();
  // this is bad
  if(sb.toString().equals("")) {}
  // this is good
  if(sb.length() == 0) {}
 }
}

  
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.strings.AppendCharacterWithChar" message="Avoid appending characters as strings in StringBuffer.append." name="AppendCharacterWithChar">
        <description>
Avoid concatenating characters as strings in StringBuffer.append.
    </description>
        <example><![CDATA[

public class Foo {
 void bar() {
  StringBuffer sb=new StringBuffer();
  // Avoid this
  sb.append("a");

  // use instead something like this
  StringBuffer sb=new StringBuffer();
  sb.append('a');
 }
}

    ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.strings.ConsecutiveLiteralAppends" message="StringBuffer.append is called {0} consecutive times with literal Strings. Use a single append with a single String." name="ConsecutiveLiteralAppends">
        <description>
Consecutively calling StringBuffer.append with String literals
    </description>
        <example><![CDATA[

public class Foo {
 private void bar() {
   StringBuffer buf = new StringBuffer();
   buf.append("Hello").append(" ").append("World"); //bad
   buf.append("Hello World");//good
 }
}

    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="threshold" value="1"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.strings.UseIndexOfChar" message="String.indexOf(char) is faster than String.indexOf(String)." name="UseIndexOfChar">
        <description>
Use String.indexOf(char) when checking for the index of a single character; it executes faster.
    </description>
        <example><![CDATA[

public class Foo {
 void bar() {
  String s = "hello world";
  // avoid this
  if (s.indexOf("d") {}
  // instead do this
  if (s.indexOf('d') {}
 }
}

    ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.strings.InefficientEmptyStringCheck" message="String.trim().length()==0 is an inefficient way to validate an empty String." name="InefficientEmptyStringCheck">
        <description>
String.trim().length() is an inefficient way to check if a String is really empty, as it 
creates a new String object just to check its size. Consider creating a static function that
loops through a string, checking Character.isWhitespace() on each character and returning
false if a non-whitespace character is found.
    </description>
        <example><![CDATA[

public class Foo {
    void bar(String string) {
        if (string != null && string.trim().size() > 0) { 
		    doSomething();
        } 
    }
}

    ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.strings.InsufficientStringBufferDeclaration" message="StringBuffer constructor is initialized with size {0}, but has at least {1} characters appended." name="InsufficientStringBufferDeclaration">
        <description>
Failing to pre-size a StringBuffer properly could cause it to re-size many times 
during runtime. This rule checks the characters that are actually passed into
StringBuffer.append(), but represents a best guess "worst case" scenario. An 
empty StringBuffer constructor initializes the object to 16 characters. This default 
is assumed if the length of the constructor can not be determined.
    </description>
        <example><![CDATA[

public class Foo {
    void bar() {
        StringBuffer bad = new StringBuffer();
        bad.append("This is a long string, will exceed the default 16 characters");//bad 
        StringBuffer good = new StringBuffer(41);
        good.append("This is a long string, which is pre-sized");//good
    }
}

    ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.strings.UselessStringValueOf" message="No need to call String.valueOf to append to a string." name="UselessStringValueOf">
        <description>
No need to call String.valueOf to append to a string; just use the valueOf() argument directly.
      </description>
        <example><![CDATA[

public String convert(int i) {
  String s;
  s = "a" + String.valueOf(i); // Bad
  s = "a" + i; // Better
  return s;
}

          ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Do not instantiate a StringBuffer with a char" name="StringBufferInstantiationWithChar">
        <description>
StringBuffer sb = new StringBuffer('c'); The
char will be converted into int to intialize
StringBuffer size.
    </description>
        <example><![CDATA[

class Foo {
  StringBuffer sb1 = new StringBuffer('c'); //Bad
  StringBuffer sb2 = new StringBuffer("c"); //Better
}

    ]]></example>
        <priority>4</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//AllocationExpression/ClassOrInterfaceType
[@Image='StringBuffer']
/../Arguments/ArgumentList/Expression/PrimaryExpression
/PrimaryPrefix/
Literal
  [starts-with(@Image, "'")]
  [ends-with(@Image, "'")]

            ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Use equals() to compare strings instead of ''=='' or ''!=''" name="UseEqualsToCompareStrings">
        <description>
Using '==' or '!=' to compare strings only works if intern version is used on both sides
    </description>
        <example><![CDATA[

class Foo {
  boolean test(String s) {
    if (s == "one") return true; //Bad
    if ("two".equals(s)) return true; //Better
    return false;
  }
}

    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//EqualityExpression/PrimaryExpression/PrimaryPrefix/Literal
   [starts-with(@Image, '"')]
   [ends-with(@Image, '"')]

            ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="You have a suite() method that is not both public and static, so JUnit won't call it to get your TestSuite.  Is that what you wanted to do?" name="JUnitStaticSuite">
        <description>
The suite() method in a JUnit test needs to be both public and static.
      </description>
        <example><![CDATA[
  
import junit.framework.*;
public class Foo extends TestCase {
 public void suite() {} // oops, should be static
 private static void suite() {} // oops, should be public
}
  
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                
//MethodDeclaration[not(@Static='true') or not(@Public='true')]
[MethodDeclarator/@Image='suite']
[MethodDeclarator/FormalParameters/@ParameterCount=0]
[ancestor::ClassOrInterfaceDeclaration[//ClassOrInterfaceType[typeof(@Image, 'junit.framework.TestCase','TestCase')] or //MarkerAnnotation/Name[typeof(@Image, 'org.junit.Test', 'Test')]]]
                
            ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="You may have misspelled a JUnit framework method (setUp or tearDown)" name="JUnitSpelling">
        <description>
Some JUnit framework methods are easy to misspell.
    </description>
        <example><![CDATA[

import junit.framework.*;
public class Foo extends TestCase {
 public void setup() {} // oops, should be setUp
 public void TearDown() {} // oops, should be tearDown
}

    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
              
//MethodDeclarator[(not(@Image = 'setUp')
 and translate(@Image, 'SETuP', 'setUp') = 'setUp')
 or (not(@Image = 'tearDown')
 and translate(@Image, 'TEARdOWN', 'tearDown') = 'tearDown')]
 [FormalParameters[count(*) = 0]]
[ancestor::ClassOrInterfaceDeclaration[//ClassOrInterfaceType[typeof(@Image, 'junit.framework.TestCase','TestCase')] or //MarkerAnnotation/Name[typeof(@Image, 'org.junit.Test', 'Test')]]]
              
          ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.junit.JUnitAssertionsShouldIncludeMessage" message="JUnit assertions should include a message" name="JUnitAssertionsShouldIncludeMessage">
        <description>
JUnit assertions should include a message - i.e., use the three argument version of
assertEquals(), not the two argument version.
      </description>
        <example><![CDATA[
  
public class Foo extends TestCase {
 public void testSomething() {
  assertEquals("foo", "bar");
  // Use the form:
  // assertEquals("Foo does not equals bar", "foo", "bar");
  // instead
 }
}
  
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.junit.JUnitTestsShouldContainAsserts" message="JUnit tests should include assert() or fail()" name="JUnitTestsShouldIncludeAssert">
        <description>
JUnit tests should include at least one assertion.  This makes the tests more robust, and
 using assert with messages provide the developer a clearer idea of what the test does.
        </description>
        <example><![CDATA[
    
public class Foo extends TestCase {
  public void testSomething() {
      Bar b = findBar();
  // This is better than having a NullPointerException
  // assertNotNull("bar not found", b);
  b.work();
  }
}
    
        ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.junit.TestClassWithoutTestCases" message="This class name ends with 'Test' but contains no test cases" name="TestClassWithoutTestCases">
        <description>
Test classes end with the suffix Test. Having a non-test class with that name is
not a good practice, since most people will assume it is a test case. Test
classes have test methods named testXXX.
      </description>
        <example><![CDATA[

//Consider changing the name of the class if it is not a test
//Consider adding test methods if it is a test
public class CarTest {
   public static void main(String[] args) {
    // do something
   }
   // code
}

      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="assertTrue(true) or similar statements are unnecessary" name="UnnecessaryBooleanAssertion">
        <description>
A JUnit test assertion with a boolean literal is unnecessary since it always will eval to the same thing.
Consider using flow control (in case of assertTrue(false) or similar) or simply removing
statements like assertTrue(true) and assertFalse(false).  If you just want a test to halt, use the fail method.
      </description>
        <example><![CDATA[

public class SimpleTest extends TestCase {
 public void testX() {
  // Why on earth would you write this?
  assertTrue(true);
 }
}

          ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//StatementExpression
[
.//Name[@Image='assertTrue' or  @Image='assertFalse']
and
PrimaryExpression/PrimarySuffix/Arguments/ArgumentList
 /Expression/PrimaryExpression/PrimaryPrefix
  /Literal/BooleanLiteral
or
(
.//Name[@Image='assertTrue' or  @Image='assertFalse']
and
PrimaryExpression/PrimarySuffix/Arguments/ArgumentList
 /Expression/UnaryExpressionNotPlusMinus[@Image='!']
/PrimaryExpression/PrimaryPrefix[Literal/BooleanLiteral or Name[count(../../*)=1]])
]
[ancestor::ClassOrInterfaceDeclaration[//ClassOrInterfaceType[typeof(@Image, 'junit.framework.TestCase','TestCase')] or //MarkerAnnotation/Name[typeof(@Image, 'org.junit.Test', 'Test')]]]

              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Use assertEquals(x, y) instead of assertTrue(x.equals(y))" name="UseAssertEqualsInsteadOfAssertTrue">
        <description>
This rule detects JUnit assertions in object equality. These assertions
should be made by more specific methods, like assertEquals.
      </description>
        <example><![CDATA[

public class FooTest extends TestCase {
 void testCode() {
  Object a, b;
  assertTrue(a.equals(b)); // bad usage
  assertEquals(?a should equals b?, a, b); // good usage
 }
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                
//PrimaryExpression[
    PrimaryPrefix/Name[@Image = 'assertTrue']
][
    PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix/Name
    [ends-with(@Image, '.equals')]
]
[ancestor::ClassOrInterfaceDeclaration[//ClassOrInterfaceType[typeof(@Image, 'junit.framework.TestCase','TestCase')] or //MarkerAnnotation/Name[typeof(@Image, 'org.junit.Test', 'Test')]]]
 
            ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Use assertSame(x, y) instead of assertTrue(x==y), or assertNotSame(x,y) vs assertFalse(x==y)" name="UseAssertSameInsteadOfAssertTrue">
        <description>
This rule detects JUnit assertions in object references equality. These assertions
should be made by more specific methods, like assertSame, assertNotSame.
      </description>
        <example><![CDATA[

public class FooTest extends TestCase {
 void testCode() {
  Object a, b;
  assertTrue(a==b); // bad usage
  assertSame(a, b);  // good usage
 }
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                
//PrimaryExpression[
    PrimaryPrefix/Name
     [@Image = 'assertTrue' or @Image = 'assertFalse']
]
[PrimarySuffix/Arguments
 /ArgumentList/Expression
 /EqualityExpression[count(.//NullLiteral) = 0]]
[ancestor::ClassOrInterfaceDeclaration[//ClassOrInterfaceType[typeof(@Image, 'junit.framework.TestCase','TestCase')] or //MarkerAnnotation/Name[typeof(@Image, 'org.junit.Test', 'Test')]]]
 
            ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Use assertNull(x) instead of assertTrue(x==null), or assertNotNull(x) vs assertFalse(x==null)" name="UseAssertNullInsteadOfAssertTrue">
        <description>
 This rule detects JUnit assertions in object references equality. These assertions
 should be made by more specific methods, like assertNull, assertNotNull.
       </description>
        <example><![CDATA[
 
 public class FooTest extends TestCase {
  void testCode() {
   Object a = doSomething();
   assertTrue(a==null); // bad usage
   assertNull(a);  // good usage
   assertTrue(a != null); // bad usage
   assertNotNull(a);  // good usage
  }
 }
 
       ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                 
//PrimaryExpression[
 PrimaryPrefix/Name[@Image = 'assertTrue' or @Image = 'assertFalse']
][
 PrimarySuffix/Arguments/ArgumentList[
  Expression/EqualityExpression/PrimaryExpression/PrimaryPrefix/Literal/NullLiteral
 ]
]
[ancestor::ClassOrInterfaceDeclaration[//ClassOrInterfaceType[typeof(@Image, 'junit.framework.TestCase','TestCase')] or //MarkerAnnotation/Name[typeof(@Image, 'org.junit.Test', 'Test')]]]
  
             ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="assertTrue(!expr) can be replaced by assertFalse(expr)" name="SimplifyBooleanAssertion">
        <description>
Avoid negation in an assertTrue or assertFalse test.
For example, rephrase:
assertTrue(!expr);
as:
assertFalse(expr);
      </description>
        <example><![CDATA[

public class SimpleTest extends TestCase {
 public void testX() {
  assertTrue("not empty", !r.isEmpty()); // replace with assertFalse("not empty", r.isEmpty())
  assertFalse(!r.isEmpty()); // replace with assertTrue(r.isEmpty())
 }
}

          ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//StatementExpression
[
.//Name[@Image='assertTrue' or  @Image='assertFalse']
and
PrimaryExpression/PrimarySuffix/Arguments/ArgumentList
 /Expression/UnaryExpressionNotPlusMinus[@Image='!']
/PrimaryExpression/PrimaryPrefix
]
[ancestor::ClassOrInterfaceDeclaration[//ClassOrInterfaceType[typeof(@Image, 'junit.framework.TestCase','TestCase')] or //MarkerAnnotation/Name[typeof(@Image, 'org.junit.Test', 'Test')]]]

              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.sunsecure.MethodReturnsInternalArray" message="Returning ''{0}'' may expose an internal array." name="MethodReturnsInternalArray">
        <description>
Exposing internal arrays directly allows the user to modify some code that could be critical.
It is safer to return a copy of the array.
      </description>
        <example><![CDATA[
  
public class SecureSystem {
  UserData [] ud;
  public UserData [] getUserData() {
      // Don't return directly the internal array, return a copy
      return ud;
  }
}
  
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.sunsecure.ArrayIsStoredDirectly" message="The user-supplied array ''{0}'' is stored directly." name="ArrayIsStoredDirectly">
        <description>Constructors and methods receiving arrays should clone objects and store the copy.
This prevents that future changes from the user affect the internal functionality.</description>
        <example><![CDATA[public class Foo {
 private String [] x;
  public void foo (String [] param) {
      // Don't do this, make a copy of the array at least
      this.x=param;
  }
}]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.NpathComplexity" message="The method {0}() has an NPath complexity of {1}" name="NPathComplexity">
        <description>
   The NPath complexity of a method is the number of acyclic execution paths through that method.
   A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
   </description>
        <example><![CDATA[
 
 public class Foo {
  void bar() {
   // lots of complicated code
  }
 }
 
    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="minimum" value="200"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.LongMethodRule" message="Avoid really long methods." name="ExcessiveMethodLength">
        <description>
Violations of this rule usually indicate that the method is doing
too much.  Try to reduce the method size by creating helper methods and removing any copy/pasted code.
   </description>
        <example><![CDATA[

public class Foo {
 public void doSomething() {
  System.out.println("Hello world!");
  System.out.println("Hello world!");
  // 98 copies omitted for brevity.
 }
}

   ]]></example>
        <priority>3</priority>
        <properties>
            <property name="minimum" value="100"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.LongParameterListRule" message="Avoid really long parameter lists." name="ExcessiveParameterList">
        <description>
Long parameter lists can indicate that a new object should be created to
 wrap the numerous parameters.  Basically, try to group the parameters together.
   </description>
        <example><![CDATA[

public class Foo {
 public void addData(
  int p0, int p1, int p2, int p3, int p4, int p5,
  int p5, int p6, int p7, int p8, int p9, int p10) {
  }
 }
}

   ]]></example>
        <priority>3</priority>
        <properties>
            <property name="minimum" value="10"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.LongClassRule" message="Avoid really long classes." name="ExcessiveClassLength">
        <description>
Long Class files are indications that the class may be trying to
do too much.  Try to break it down, and reduce the size to something
manageable.
   </description>
        <example><![CDATA[

public class Foo {
  public void bar() {
    // 1000 lines of code
  }
}

   ]]></example>
        <priority>3</priority>
        <properties>
            <property name="minimum" value="1000"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.CyclomaticComplexity" message="The {0} ''{1}'' has a Cyclomatic Complexity of {2}." name="CyclomaticComplexity">
        <description>
Complexity is determined by the number of decision points in a method plus one for the
method entry.  The decision points are 'if', 'while', 'for', and 'case labels'.  Generally,
1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity,
 and 11+ is very high complexity.
   </description>
        <example><![CDATA[

// Cyclomatic Complexity = 12
public class Foo {
1   public void example()  {
2       if (a == b)  {
3           if (a1 == b1) {
                fiddle();
4           } else if a2 == b2) {
                fiddle();
            }  else {
                fiddle();
            }
5       } else if (c == d) {
6           while (c == d) {
                fiddle();
            }
7        } else if (e == f) {
8           for (int n = 0; n < h; n++) {
                fiddle();
            }
        } else{
            switch (z) {
9               case 1:
                    fiddle();
                    break;
10              case 2:
                    fiddle();
                    break;
11              case 3:
                    fiddle();
                    break;
12              default:
                    fiddle();
                    break;
            }
        }
    }
}

   ]]></example>
        <priority>3</priority>
        <properties>
            <property name="reportLevel" value="10"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.ExcessivePublicCount" message="This class has a bunch of public methods and attributes" name="ExcessivePublicCount">
        <description>
A large number of public methods and attributes declared in a class can indicate the
 class may need to be broken up as increased effort will be required to thoroughly test it.
    </description>
        <example><![CDATA[
    
public class Foo {
 public String value;
 public Bar something;
 public Variable var;
 // [... more more public attributes ...]
 public void doWork() {}
 public void doMoreWork() {}
 public void doWorkAgain() {}
 // [... more more public methods ...]
}
    
    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="minimum" value="45"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.TooManyFields" message="Too many fields" name="TooManyFields">
        <description>
Classes that have too many fields could be redesigned to have fewer fields, possibly
 through some nested object grouping of some of the information.  For example, a class with
 city/state/zip fields could instead have one Address field.
      </description>
        <example><![CDATA[
   
public class Person {
   String one;
   int two;
   int three;
   [... many more public fields ...]
}
   
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="maxfields" value="15"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.codesize.NcssMethodCount" message="The method {0}() has an NCSS line count of {1}" name="NcssMethodCount">
        <description>
This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines
of code for a given method. NCSS ignores comments, and counts actual statements. Using this algorithm, 
lines of code that are split are counted as one.
    </description>
        <example><![CDATA[

public class Foo extends Bar {
 public int methd() {
     super.methd();
 
 
 
 
 
 //this method only has 1 NCSS lines
      return 1;
 }
}

   ]]></example>
        <priority>3</priority>
        <properties>
            <property name="minimum" value="100"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.codesize.NcssTypeCount" message="The type has an NCSS line count of {0}" name="NcssTypeCount">
        <description>
This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines
of code for a given type. NCSS ignores comments, and counts actual statements. Using this algorithm, 
lines of code that are split are counted as one.
    </description>
        <example><![CDATA[

public class Foo extends Bar {
 public Foo() {
 //this class only has 6 NCSS lines
     super();
 
 
 
 
 
      super.foo();
 }
}

   ]]></example>
        <priority>3</priority>
        <properties>
            <property name="minimum" value="1500"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.codesize.NcssConstructorCount" message="The constructor with {0} parameters has an NCSS line count of {1}" name="NcssConstructorCount">
        <description>
This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines
of code for a given constructor. NCSS ignores comments, and counts actual statements. Using this algorithm, 
lines of code that are split are counted as one.
    </description>
        <example><![CDATA[

public class Foo extends Bar {
 public Foo() {
     super();
 
 
 
 
 
 //this constructor only has 1 NCSS lines
      super.foo();
 }
}

   ]]></example>
        <priority>3</priority>
        <properties>
            <property name="minimum" value="100"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="In J2EE, getClassLoader() might not work as expected.  Use Thread.currentThread().getContextClassLoader() instead." name="UseProperClassLoader">
        <description>
    In J2EE getClassLoader() might not work as expected.  Use Thread.currentThread().getContextClassLoader() instead.
   </description>
        <example><![CDATA[

public class Foo {
 ClassLoader cl = Bar.class.getClassLoader();
}

  ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//PrimarySuffix[@Image='getClassLoader']
 
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="SessionBean or MessageBean should be suffixed by Bean" name="MDBAndSessionBeanNamingConvention">
        <description>
        The EJB Specification state that any MessageDrivenBean or SessionBean should be suffixed by Bean.
        </description>
        <example><![CDATA[
            
            /* Proper name */
            public class SomeBean implements SessionBean{}
            
        ]]></example>
        <priority>4</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
//TypeDeclaration/ClassOrInterfaceDeclaration
[
    (
        (./ImplementsList/ClassOrInterfaceType[ends-with(@Image,'SessionBean')])
        or
        (./ImplementsList/ClassOrInterfaceType[ends-with(@Image,'MessageDrivenBean')])
    )
    and
    not
    (
        ends-with(@Image,'Bean')
    )
]
             ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Remote Home interface of a Session EJB should be suffixed by 'Home'" name="RemoteSessionInterfaceNamingConvention">
        <description>
        Remote Home interface of a Session EJB should be suffixed by 'Home'.
        </description>
        <example><![CDATA[
            
            /* Proper name */
            public interface MyBeautifulHome extends javax.ejb.EJBHome {}
            
        ]]></example>
        <priority>4</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                    
//ClassOrInterfaceDeclaration
[
    (
        (./ExtendsList/ClassOrInterfaceType[ends-with(@Image,'EJBHome')])
    )
    and
    not
    (
        ends-with(@Image,'Home')
    )
]
                    
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="The Local Interface of a Session EJB should be suffixed by 'Local'" name="LocalInterfaceSessionNamingConvention">
        <description>
        The Local Interface of a Session EJB should be suffixed by 'Local'.
        </description>
        <example><![CDATA[
            
            /* Proper name */
            public interface MyLocal extends javax.ejb.EJBLocalObject {}
            
        ]]></example>
        <priority>4</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                    
//ClassOrInterfaceDeclaration
[
    (
        (./ExtendsList/ClassOrInterfaceType[ends-with(@Image,'EJBLocalObject')])
    )
    and
    not
    (
        ends-with(@Image,'Local')
    )
]
                    
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="The Local Home interface of a Session EJB should be suffixed by 'LocalHome'" name="LocalHomeNamingConvention">
        <description>
        The Local Home interface of a Session EJB should be suffixed by 'LocalHome'.
        </description>
        <example><![CDATA[
            
            /* Proper name */
            public interface MyBeautifulLocalHome extends javax.ejb.EJBLocalHome {}
            
        ]]></example>
        <priority>4</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                    
//ClassOrInterfaceDeclaration
[
    (
        (./ExtendsList/ClassOrInterfaceType[ends-with(@Image,'EJBLocalHome')])
    )
    and
    not
    (
        ends-with(@Image,'LocalHome')
    )
]
                    
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Remote Interface of a Session EJB should NOT be suffixed" name="RemoteInterfaceNamingConvention">
        <description>
        Remote Interface of a Session EJB should NOT be suffixed.
        </description>
        <example><![CDATA[
            
            /* Bad Session suffix */
            public interface BadSuffixSession extends javax.ejb.EJBObject {}
            
        ]]></example>
        <priority>4</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                    
//ClassOrInterfaceDeclaration
[
    (
        (./ExtendsList/ClassOrInterfaceType[ends-with(@Image,'EJBObject')])
    )
    and
    (
        ends-with(@Image,'Session')
        or
        ends-with(@Image,'EJB')
        or
        ends-with(@Image,'Bean')
    )
]
                    
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="System.exit() should not be used in J2EE/JEE apps" name="DoNotCallSystemExit">
        <description>
Web applications should not call System.exit(), since only the web container or the
application server should stop the JVM.
     </description>
        <example><![CDATA[
    		
public class Foo {
    public void bar() {
        // NEVER DO THIS IN A APP SERVER !!!
        System.exit(0);
    }
}
     ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
//Name[starts-with(@Image,'System.exit')]
    		]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="EJB's shouldn't have non-final static fields" name="StaticEJBFieldShouldBeFinal">
        <description>
According to the J2EE specification (p.494), an EJB should not have any static fields
with write access. However, static read only fields are allowed. This ensures proper
behavior especially when instances are distributed by the container on several JREs.
    	</description>
        <example><![CDATA[
public class SomeEJB extends EJBObject implements EJBLocalHome {
	private static int BAD_STATIC_FIELD;

	private static final int GOOD_STATIC_FIELD;
}
     ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
//ClassOrInterfaceDeclaration[
    (
    (./ImplementsList/ClassOrInterfaceType[ends-with(@Image,'SessionBean')])
    or
    (./ImplementsList/ClassOrInterfaceType[ends-with(@Image,'EJBHome')])
    or
    (./ImplementsList/ClassOrInterfaceType[ends-with(@Image,'EJBLocalObject')])
    or
    (./ImplementsList/ClassOrInterfaceType[ends-with(@Image,'EJBLocalHome')])
    or
    (./ExtendsList/ClassOrInterfaceType[ends-with(@Image,'EJBObject')])
    )
    and
    (./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration[
         (./FieldDeclaration[@Static = 'true'])
         and
         (./FieldDeclaration[@Final = 'false'])
    ])
]
    		 ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="To be compliant to J2EE, a webapp should not use any thread." name="DoNotUseThreads">
        <description>
            
                The J2EE specification explicitly forbid use of threads.
            
        </description>
        <example><![CDATA[
            	
            // This is not allowed
            public class UsingThread extends Thread {

            }
			// Neither this,
			public class OtherThread implements Runnable {
				// Nor this ...
				public void methode() {
					Runnable thread = new Thread(); thread.run();
				}
			}
				
		]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                    
                        //ClassOrInterfaceType[@Image = 'Thread' or @Image = 'Runnable']
                    
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.UseSingleton" message="All methods are static.  Consider using Singleton instead.  Alternatively, you could add a private constructor or make the class abstract to silence this warning." name="UseSingleton">
        <description>
If you have a class that has nothing but static methods, consider making it a Singleton.
Note that this doesn't apply to abstract classes, since their subclasses may
well include non-static methods.  Also, if you want this class to be a Singleton,
remember to add a private constructor to prevent instantiation.
    </description>
        <example><![CDATA[

public class MaybeASingleton {
 public static void foo() {}
 public static void bar() {}
}

    ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.SimplifyBooleanReturns" message="Avoid unnecessary if..then..else statements when returning a boolean" name="SimplifyBooleanReturns">
        <description>
Avoid unnecessary if..then..else statements when returning a boolean.
    </description>
        <example><![CDATA[

public class Foo {
  private int bar =2;
  public boolean isBarEqualsTo(int x) {
    // this bit of code
    if (bar == x) {
     return true;
    } else {
     return false;
    }
    // can be replaced with a simple
    // return bar == x;
  }
}

    ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid unnecessary comparisons in boolean expressions" name="SimplifyBooleanExpressions">
        <description>
Avoid unnecessary comparisons in boolean expressions - this complicates simple code.
      </description>
        <example><![CDATA[
  
public class Bar {
 // can be simplified to
 // bar = isFoo();
 private boolean bar = (isFoo() == true);

 public isFoo() { return false;}
}
  
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//EqualityExpression/PrimaryExpression
 /PrimaryPrefix/Literal/BooleanLiteral

              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Switch statements should have a default label" name="SwitchStmtsShouldHaveDefault">
        <description>
Switch statements should have a default label.
    </description>
        <example><![CDATA[

public class Foo {
 public void bar() {
  int x = 2;
  switch (x) {
   case 2: int j = 8;
  }
 }
}

    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                  
//SwitchStatement[not(SwitchLabel[@Default='true'])]
                  
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.AvoidDeeplyNestedIfStmtsRule" message="Deeply nested if..then statements are hard to read" name="AvoidDeeplyNestedIfStmts">
        <description>
Deeply nested if..then statements are hard to read.
    </description>
        <example><![CDATA[

public class Foo {
 public void bar(int x, int y, int z) {
  if (x>y) {
   if (y>z) {
    if (z==x) {
     // whew, too deep
    }
   }
  }
 }
}

    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="problemDepth" value="3"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.AvoidReassigningParameters" message="Avoid reassigning parameters such as ''{0}''" name="AvoidReassigningParameters">
        <description>
Reassigning values to parameters is a questionable practice.  Use a temporary local variable instead.
    </description>
        <example><![CDATA[

public class Foo {
 private void foo(String bar) {
  bar = "something else";
 }
}

    ]]></example>
        <priority>2</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.SwitchDensityRule" message="A high ratio of statements to labels in a switch statement.  Consider refactoring." name="SwitchDensity">
        <description>
 A high ratio of statements to labels in a switch statement implies that the switch
 statement is doing too much work.  Consider moving the statements into new
 methods, or creating subclasses based on the switch variable.
      </description>
        <example><![CDATA[
 
public class Foo {
 public void bar(int x) {
   switch (x) {
     case 1: {
       // lots of statements
       break;
     } case 2: {
       // lots of statements
       break;
     }
   }
 }
}
 
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="minimum" value="10"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.ConstructorCallsOverridableMethod" message="Overridable {0} called during object construction" name="ConstructorCallsOverridableMethod">
        <description>
Calling overridable methods during construction poses a risk of invoking methods on an
incompletely constructed object and 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.   Note that this includes method calls
throughout the control flow graph - i.e., if a constructor Foo() calls a private method
bar() that calls a public method buz(), this denotes a problem.
      </description>
        <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.toUpperCase();
  }
}
  
      ]]></example>
        <priority>1</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.AccessorClassGeneration" message="Avoid instantiation through private constructors from outside of the constructor's class." name="AccessorClassGeneration">
        <description>
Instantiation by way of private constructors from outside of the constructor's class often causes the generation of an accessor.
A factory method, or non-privitization of the constructor can eliminate this situation.
The generated class file is actually an interface.  It gives the accessing class the ability to invoke a new hidden package
scope constructor that takes the interface as a supplementary parameter.  This turns a private constructor effectively into
one with package scope, and is challenging to discern.
      </description>
        <example><![CDATA[
  
public class Outer {
 void method(){
  Inner ic = new Inner();//Causes generation of accessor class
 }
 public class Inner {
  private Inner(){}
 }
}
  
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="This final field could be made static" name="FinalFieldCouldBeStatic">
        <description>
If a final field is assigned to a compile-time constant, it could be
made static, thus saving overhead in each object at runtime.
      </description>
        <example><![CDATA[
  
public class Foo {
 public final int BAR = 42; // this could be static and save some space
}
  
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                    
//FieldDeclaration
 [@Final='true' and @Static='false']
 [not (../../../../ClassOrInterfaceDeclaration[@Interface='true'])]
   /VariableDeclarator/VariableInitializer/Expression
    /PrimaryExpression/PrimaryPrefix/Literal
                    
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.CloseResource" message="Ensure that resources like this {0} object are closed after use" name="CloseResource">
        <description>
Ensure that resources (like Connection, Statement, and ResultSet objects) are always closed after use.
    </description>
        <example><![CDATA[

public class Bar {
 public void foo() {
  Connection c = pool.getConnection();
  try {
    // do stuff
  } catch (SQLException ex) {
    // handle exception
  } finally {
    // oops, should close the connection using 'close'!
    // c.close();
  }
 }
}

    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="types" value="Connection,Statement,ResultSet"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Non-static initializers are confusing" name="NonStaticInitializer">
        <description>
A nonstatic initializer block will be called any time a constructor
is invoked (just prior to invoking the constructor).  While this
is a valid language construct, it is rarely used and is confusing.
       </description>
        <example><![CDATA[
   
public class MyClass {
 // this block gets run before any call to a constructor
 {
  System.out.println("I am about to construct myself");
 }
}
   
       ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//Initializer[@Static='false']

                 ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="The default label should be the last label in a switch statement" name="DefaultLabelNotLastInSwitchStmt">
        <description>
By convention, the default label should be the last label in a switch statement.
       </description>
        <example><![CDATA[
   
public class Foo {
 void bar(int a) {
  switch (a) {
   case 1:  // do something
      break;
   default:  // the default case should be last, by convention
      break;
   case 2:
      break;
  }
 }
}   
       ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//SwitchStatement
 [not(SwitchLabel[position() = last()][@Default='true'])]
 [SwitchLabel[@Default='true']]

                 ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="A non-case label was present in a switch statement" name="NonCaseLabelInSwitchStatement">
        <description>
A non-case label (e.g. a named break/continue label) was present in a switch statement.
This legal, but confusing. It is easy to mix up the case labels and the non-case labels.
       </description>
        <example><![CDATA[
   
public class Foo {
 void bar(int a) {
  switch (a) {
   case 1:
      // do something
      break;
   mylabel: // this is legal, but confusing!
      break;
   default:
      break;
  }
 }
}
   
       ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
 
//SwitchStatement//BlockStatement/Statement/LabeledStatement
 
                 ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="This call to Collection.toArray() may be optimizable" name="OptimizableToArrayCall">
        <description>
A call to Collection.toArray can use the Collection's size vs an empty Array of the desired type.
      </description>
        <example><![CDATA[
  
class Foo {
 void bar(Collection x) {
   // A bit inefficient
   x.toArray(new Foo[0]);
   // Much better; this one sizes the destination array, avoiding
   // a reflection call in some Collection implementations
   x.toArray(new Foo[x.size()]);
 }
}
  
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                  
//PrimaryExpression
[PrimaryPrefix/Name[ends-with(@Image, 'toArray')]]
[
PrimarySuffix/Arguments/ArgumentList/Expression
 /PrimaryExpression/PrimaryPrefix/AllocationExpression
 /ArrayDimsAndInits/Expression/PrimaryExpression/PrimaryPrefix/Literal[@Image='0']
]

                  
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid equality comparisons with Double.NaN" name="BadComparison">
        <description>
Avoid equality comparisons with Double.NaN - these are likely to be logic errors.
      </description>
        <example><![CDATA[
  
public class Bar {
 boolean x = (y == Double.NaN);
}
  
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                  
//EqualityExpression[@Image='==']
 /PrimaryExpression/PrimaryPrefix
 /Name[@Image='Double.NaN' or @Image='Float.NaN']
                  
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid using equals() to compare against null" name="EqualsNull">
        <description>
Inexperienced programmers sometimes confuse comparison concepts
and use equals() to compare to null.
        </description>
        <example><![CDATA[
       
class Bar {
   void foo() {
       String x = "foo";
       if (x.equals(null)) { // bad!
        doSomething();
       }
   }
}
    
        ]]></example>
        <priority>1</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//PrimaryExpression
 [
PrimaryPrefix/Name[ends-with(@Image, 'equals')]
or
PrimarySuffix[ends-with(@Image, 'equals')]
]
[PrimarySuffix/Arguments/ArgumentList[count(Expression)=1]
  /Expression/PrimaryExpression/PrimaryPrefix
   /Literal/NullLiteral]
    
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.ConfusingTernary" message="Avoid if (x != y) ..; else ..;" name="ConfusingTernary">
        <description>
In an "if" expression with an "else" clause, avoid negation in
the test.  For example, rephrase:
if (x != y) diff(); else same();
as:
if (x == y) same(); else diff();
Most "if (x != y)" cases without an "else" are often return
cases, so consistent use of this rule makes the code easier
to read.  Also, this resolves trivial ordering problems, such
as "does the error case go first?" or "does the common case
go first?".
        </description>
        <example><![CDATA[
          
public class Foo {
 boolean bar(int x, int y) {
  return (x != y) ? diff : same;
 }
}          
        ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid instantiating an object just to call getClass() on it; use the .class public member instead" name="InstantiationToGetClass">
        <description>
Avoid instantiating an object just to call getClass() on it; use the .class public member instead.
      </description>
        <example><![CDATA[
    
public class Foo {
 // Replace this
 Class c = new String().getClass();
 // with this:
 Class c = String.class;
}
    
        ]]></example>
        <priority>4</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                
//PrimarySuffix
 [@Image='getClass']
 [parent::PrimaryExpression
  [PrimaryPrefix/AllocationExpression]
  [count(PrimarySuffix) = 2]
 ]
     
            ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.IdempotentOperations" message="Avoid idempotent operations (like assigning a variable to itself)." name="IdempotentOperations">
        <description>
Avoid idempotent operations - they are have no effect.
      </description>
        <example><![CDATA[
      
public class Foo {
 public void bar() {
  int x = 2;
  x = x;
 }
}
      
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="When instantiating a SimpleDateFormat object, specify a Locale" name="SimpleDateFormatNeedsLocale">
        <description>
Be sure to specify a Locale when creating a new instance of SimpleDateFormat.
        </description>
        <example><![CDATA[
        
public class Foo {
 // Should specify Locale.US (or whatever)
 private SimpleDateFormat sdf = new SimpleDateFormat("pattern");
}
        
        ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//AllocationExpression
 [ClassOrInterfaceType[@Image='SimpleDateFormat']]
 [Arguments[@ArgumentCount=1]]

                    ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.ImmutableField" message="Private field ''{0}'' could be made final; it is only initialized in the declaration or constructor." name="ImmutableField">
        <description>
Identifies private fields whose values never change once they are initialized either in the declaration of the field or by
a constructor.  This aids in converting existing classes to immutable classes.
      </description>
        <example><![CDATA[
  
public class Foo {
  private int x; // could be final
  public Foo() {
      x = 7;
  }
  public void foo() {
     int a = x + 2;
  }
}
  
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="When doing a String.toLowerCase()/toUpperCase() call, use a Locale" name="UseLocaleWithCaseConversions">
        <description>
When doing a String.toLowerCase()/toUpperCase() call, use a Locale.  This avoids
problems with certain locales, i.e. Turkish.
      </description>
        <example><![CDATA[
    
class Foo {
 // BAD
 if (x.toLowerCase().equals("list"))...
 /*
 This will not match "LIST" when in Turkish locale
 The above could be
 if (x.toLowerCase(Locale.US).equals("list")) ...
 or simply
 if (x.equalsIgnoreCase("list")) ...
 */
 // GOOD
 String z = a.toLowerCase(Locale.EN);
}
    
        ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                
//PrimaryExpression
[PrimaryPrefix/Name
 [ends-with(@Image, 'toLowerCase') or ends-with(@Image,
'toUpperCase')]
 ]
[PrimarySuffix[position() = 1]/Arguments[@ArgumentCount=0]]
     
            ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid protected fields in a final class.  Change to private or package access." name="AvoidProtectedFieldInFinalClass">
        <description>
Do not use protected fields in final classes since they cannot be subclassed.
Clarify your intent by using private or package access modifiers instead.
         </description>
        <example><![CDATA[

public final class Bar {
 private int x;
 protected int y;  // <-- Bar cannot be subclassed, so is y really private or package visible???
 Bar() {}
}
 
         ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//ClassOrInterfaceDeclaration[@Final='true']
/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration
/FieldDeclaration[@Protected='true']
 
                 ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.AssignmentToNonFinalStatic" message="Possible unsafe assignment to a non-final static field in a constructor." name="AssignmentToNonFinalStatic">
        <description>
Identifies a possible unsafe usage of a static field.
       </description>
        <example><![CDATA[
   
public class StaticField {
   static int x;
   public FinalFields(int y) {
    x = y; // unsafe
   }
}
   
       ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Class cannot be instantiated and does not provide any static methods or fields" name="MissingStaticMethodInNonInstantiatableClass">
        <description>
A class that has private constructors and does not have any static methods or fields cannot be used.
      </description>
        <example><![CDATA[

/* This class is unusable, since it cannot be
 instantiated (private constructor),
 and no static method can be called.
 */
public class Foo {
 private Foo() {}
 void foo() {}
}


      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//ClassOrInterfaceDeclaration[@Nested='false'][
( count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration)>0
  and count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration) = count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Private='true']) )
and
count(.//MethodDeclaration[@Static='true'])=0
and
count(.//FieldDeclaration[@Private='false'][@Static='true'])=0
]
    
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Use block level rather than method level synchronization" name="AvoidSynchronizedAtMethodLevel">
        <description>
  Method level synchronization can backfire when new code is added to the method.  Block-level
  synchronization helps to ensure that only the code that needs synchronization gets it.
      </description>
        <example><![CDATA[

public class Foo {
 // Try to avoid this
 synchronized void foo() {
 }
 // Prefer this:
 void bar() {
  synchronized(this) {
  }
 }
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//MethodDeclaration[@Synchronized='true']
    
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="A switch statement does not contain a break" name="MissingBreakInSwitch">
        <description>
A switch statement without an enclosed break statement may be a bug.
      </description>
        <example><![CDATA[

public class Foo {
 public void bar(int status) {
  switch(status) {
   case CANCELLED:
    doCancelled();
    // break; hm, should this be commented out?
   case NEW:
    doNew();
   case REMOVED:
    doRemoved();
   }
 }
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//SwitchStatement
[count(.//BreakStatement)=0]
[count(SwitchLabel) > 0]
[count(BlockStatement/Statement/ReturnStatement)
 + count(BlockStatement/Statement/ThrowStatement)
     < count (SwitchLabel)]
    
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Call Thread.notifyAll() rather than Thread.notify()" name="UseNotifyAllInsteadOfNotify">
        <description>
Thread.notify() awakens a thread monitoring the object. If more than one thread is monitoring, then only
one is chosen.  The thread chosen is arbitrary; thus it's usually safer to call notifyAll() instead.
      </description>
        <example><![CDATA[

public class Foo {
 void bar() {
  x.notify();
  // If many threads are monitoring x, only one (and you won't know which) will be notified.
  // use instead:
  x.notifyAll();
 }
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//StatementExpression/PrimaryExpression
[count(PrimarySuffix/Arguments/ArgumentList) = 0]
[
PrimaryPrefix[./Name[@Image='notify' or ends-with(@Image,'.notify')]
or @Image='notify'
or (./AllocationExpression and ../PrimarySuffix[@Image='notify'])
]
]
    
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="An instanceof check is being performed on the caught exception.  Create a separate catch clause for this exception type." name="AvoidInstanceofChecksInCatchClause">
        <description>
Each caught exception type should be handled in its own catch clause.
      </description>
        <example><![CDATA[

try { // Avoid this
 // do something
} catch (Exception ee) {
 if (ee instanceof IOException) {
  cleanup();
 }
}
try {  // Prefer this:
 // do something
} catch (IOException ee) {
 cleanup();
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//CatchStatement/FormalParameter
 /following-sibling::Block//InstanceOfExpression/PrimaryExpression/PrimaryPrefix
  /Name[
   @Image = ./ancestor::Block/preceding-sibling::FormalParameter
    /VariableDeclaratorId/@Image
  ]
    
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="This abstract class does not have any abstract methods" name="AbstractClassWithoutAbstractMethod">
        <description>
The abstract class does not contain any abstract methods. An abstract class suggests
an incomplete implementation, which is to be completed by subclasses implementing the
abstract methods. If the class is intended to be used as a base class only (not to be instantiated
direcly) a protected constructor can be provided prevent direct instantiation.
      </description>
        <example><![CDATA[

public abstract class Foo {
 void int method1() { ... }
 void int method2() { ... }
 // consider using abstract methods or removing
 // the abstract modifier and adding protected constructors
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
//ClassOrInterfaceDeclaration
 [@Abstract='true'
  and count( .//MethodDeclaration[@Abstract='true'] )=0 ]
  [count(ImplementsList)=0]
  [count(.//ExtendsList)=0]
              
              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="No need to check for null before an instanceof" name="SimplifyConditional">
        <description>
No need to check for null before an instanceof; the instanceof keyword returns false when given a null argument.
          </description>
        <example><![CDATA[
      
class Foo {
 void bar(Object x) {
  if (x != null && x instanceof Bar) {
   // just drop the "x != null" check
  }
 }
}      
           ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                      
//Expression
 [ConditionalOrExpression
 [EqualityExpression[@Image='==']
  //NullLiteral
  and
  UnaryExpressionNotPlusMinus
   [@Image='!']//InstanceOfExpression[PrimaryExpression
     //Name/@Image = ancestor::ConditionalOrExpression/EqualityExpression
      /PrimaryExpression/PrimaryPrefix/Name/@Image]]
or
ConditionalAndExpression
 [EqualityExpression[@Image='!=']//NullLiteral
 and
InstanceOfExpression
 [PrimaryExpression[count(PrimarySuffix[@ArrayDereference='true'])=0]
  //Name/@Image = ancestor::ConditionalAndExpression
   /EqualityExpression/PrimaryExpression/PrimaryPrefix/Name/@Image]]]
 
                  ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.CompareObjectsWithEquals" message="Use equals() to compare object references." name="CompareObjectsWithEquals">
        <description>
 Use equals() to compare object references; avoid comparing them with ==.
  </description>
        <example><![CDATA[

class Foo {
 boolean bar(String a, String b) {
  return a == b;
 }
}


  ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Position literals first in String comparisons" name="PositionLiteralsFirstInComparisons">
        <description>
 Position literals first in String comparisons - that way if the String is null you won't get a NullPointerException, it'll just return false.
  </description>
        <example><![CDATA[

class Foo {
 boolean bar(String x) {
  return x.equals("2"); // should be "2".equals(x)
 }
}


  ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
              
//PrimaryExpression[
	PrimaryPrefix[Name
		[ends-with(@Image, '.equals')]
		]
	[../PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix/Literal]
]
[not(ancestor::Expression/ConditionalAndExpression//EqualityExpression[@Image='!=']//NullLiteral)]
[not(ancestor::Expression/ConditionalOrExpression//EqualityExpression[@Image='==']//NullLiteral)]
          
          ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.UnnecessaryLocalBeforeReturn" message="Consider simply returning the value vs storing it in local variable ''{0}''" name="UnnecessaryLocalBeforeReturn">
        <description>
Avoid unnecessarily creating local variables
      </description>
        <example><![CDATA[
  
  public class Foo {
    public int foo() {
      int x = doSomething();
      return x;  // instead, just 'return doSomething();'
    }
  }
  
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.NonThreadSafeSingleton" message="Singleton is not thread safe" name="NonThreadSafeSingleton">
        <description>
Non-thread safe singletons can result in bad state changes. Eliminate
static singletons if possible by instantiating the object directly. Static
singletons are usually not needed as only a single instance exists anyway.
Other possible fixes are to synchronize the entire method or to use an
initialize-on-demand holder class (do not use the double-check idiom).

See Effective Java, item 48.
        </description>
        <example><![CDATA[
private static Foo foo = null;

//multiple simultaneous callers may see partially initialized objects
public static Foo getFoo() {
    if (foo==null)
        foo = new Foo();
    return foo;
}
        ]]></example>
        <priority>3</priority>
        <properties>
            <property name="checkNonStaticFields" value="false"/>
            <property name="checkNonStaticMethods" value="true"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Document empty method" name="UncommentedEmptyMethod">
        <description>
Uncommented Empty Method finds instances where a method does not contain
statements, but there is no comment. By explicitly commenting empty methods
it is easier to distinguish between intentional (commented) and unintentional
empty methods.
      </description>
        <example><![CDATA[
  
public void doSomething() {
}
 
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//MethodDeclaration/Block[count(BlockStatement) = 0 and @containsComment = 'false']
 
             ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Document empty constructor" name="UncommentedEmptyConstructor">
        <description>
Uncommented Empty Constructor finds instances where a constructor does not
contain statements, but there is no comment. By explicitly commenting empty
constructors it is easier to distinguish between intentional (commented)
and unintentional empty constructors.
      </description>
        <example><![CDATA[
  
public Foo() {
  super();
}
 
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//ConstructorDeclaration[@Private='false'][count(BlockStatement) = 0 and ($ignoreExplicitConstructorInvocation = 'true' or not(ExplicitConstructorInvocation)) and @containsComment = 'false']
 
             ]]></value>
            </property>
            <property name="ignoreExplicitConstructorInvocation" value="false"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="An Interface should be used only to model a behaviour; consider converting this to a class." name="AvoidConstantsInterface">
        <description>
     An interface should be used only to model a behaviour of a
    class: using an interface as a container of constants is a poor usage pattern.
      </description>
        <example><![CDATA[
    
    public interface ConstantsInterface {
     public static final int CONSTANT1=0;
     public static final String CONSTANT2="1";
    }
    
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//ClassOrInterfaceDeclaration[@Interface="true"]
    [
     count(.//MethodDeclaration)=0
     and
     count(.//FieldDeclaration)>0
    ]
    
        ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.UnsynchronizedStaticDateFormatter" message="Static DateFormatter objects should be accessed in a synchronized manner" name="UnsynchronizedStaticDateFormatter">
        <description>
SimpleDateFormat is not synchronized. Sun recomends separate format instances
for each thread. If multiple threads must access a static formatter, the
formatter must be synchronized either on method or block level.
      </description>
        <example><![CDATA[
    
public class Foo {
    private static final SimpleDateFormat sdf = new SimpleDateFormat();
    void bar() {
        sdf.format(); // bad
    }
    synchronized void foo() {
        sdf.format(); // good
    }
}
    
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.PreserveStackTrace" message="Caught exception is rethrown, original stack trace may be lost" name="PreserveStackTrace">
        <description>
Throwing a new exception from a catch block without passing the original exception into the
new Exception will cause the true stack trace to be lost, and can make it difficult to
debug effectively.
      </description>
        <example><![CDATA[
    
public class Foo {
    void good() {
        try{
            Integer.parseInt("a");
        } catch(Exception e){
            throw new Exception(e);
        }
    }
    void bad() {
        try{
            Integer.parseInt("a");
        } catch(Exception e){
            throw new Exception(e.getMessage());
        }
    }
}
    
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.UseCollectionIsEmpty" message="Substitute calls to size() == 0 (or size() != 0) with calls to isEmpty()" name="UseCollectionIsEmpty">
        <description>
The isEmpty() method on java.util.Collection is provided to see if a collection has any elements.
Comparing the value of size() to 0 merely duplicates existing behavior.
      </description>
        <example><![CDATA[
    
	public class Foo {
		void good() {
        	List foo = getList();
			if (foo.isEmpty()) {
				// blah
			}
    	}

	    void bad() {
    	    List foo = getList();
				if (foo.size() == 0) {
					// blah
				}
	    	}
	}
    
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="A class which only has private constructors should be final" name="ClassWithOnlyPrivateConstructorsShouldBeFinal">
        <description>
A class with only private constructors should be final, unless the private 
constructor is called by a inner class.
        </description>
        <example><![CDATA[
public class Foo {  //Should be final
    private Foo() { }
}
     ]]></example>
        <priority>1</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
TypeDeclaration[count(../TypeDeclaration) = 1]/ClassOrInterfaceDeclaration
[@Final = 'false']
[count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Private = 'true']) >= 1 ]
[count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Public = 'true'])  = 0 ]
[not(.//ClassOrInterfaceDeclaration)]
             ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="An empty method in an abstract class should be abstract instead" name="EmptyMethodInAbstractClassShouldBeAbstract">
        <description>
An empty method in an abstract class should be abstract instead, as developer may rely on this empty implementation
rather than code the appropriate one.
        </description>
        <example><![CDATA[
        	
				public abstract class ShouldBeAbstract
				{
				    public Object couldBeAbstract()
				    {
					// Should be abstract method ?
					return null;
				   	}

				    public void couldBeAbstract()
				    {
				    }
				}
	     	
    	]]></example>
        <priority>1</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                
                    //ClassOrInterfaceDeclaration[@Abstract = 'true']
                        /ClassOrInterfaceBody
                        /ClassOrInterfaceBodyDeclaration
                        /MethodDeclaration[@Abstract = 'false']
                        [
                            ( boolean(./Block/BlockStatement/Statement/ReturnStatement/Expression/PrimaryExpression) = 'true' )
                            or
                            ( count (./Block/*) = 0 )
                        ]
                
             ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.SingularField" message="Perhaps ''{0}'' could be replaced by a local variable." name="SingularField">
        <description>
This field is used in only one method and the first usage is assigning a value 
to the field. This probably means that the field can be changed to a local variable.
      </description>
        <example><![CDATA[
public class Foo {
    private int x;  //Why bother saving this?
    public void foo(int y) {
     x = y + 5;
     return x;
    }
}
   ]]></example>
        <priority>3</priority>
        <properties>
            <property name="DisallowNotAssignment" value="false"/>
            <property name="CheckInnerClasses" value="false"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.CouplingBetweenObjects" message="High amount of different objects as members denotes a high coupling" name="CouplingBetweenObjects">
        <description>
This rule counts unique attributes, local variables and return types within an object. A number
 higher than specified threshold can indicate a high degree of coupling.
    </description>
        <example><![CDATA[

import com.Blah;
import org.Bar;
import org.Bardo;
public class Foo {
 private Blah var1;
 private Bar var2;
 //followed by many imports of unique objects
 void ObjectC doWork() {
  Bardo var55;
  ObjectA var44;
  ObjectZ var93;
  return something;
 }
}

    ]]></example>
        <priority>3</priority>
        <properties>
            <property name="threshold" value="20"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.ExcessiveImports" message="A high number of imports can indicate a high degree of coupling within an object." name="ExcessiveImports">
        <description>
A high number of imports can indicate a high degree of coupling within
an object. Rule counts the number of unique imports and reports a violation
if the count is above the user defined threshold.
  </description>
        <example><![CDATA[
      
import blah.blah.Baz;
import blah.blah.Bif;
// 18 others from the same package elided
public class Foo {
 public void doWork() {}
}
      
  ]]></example>
        <priority>3</priority>
        <properties>
            <property name="minimum" value="30"/>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.design.LooseCoupling" message="Avoid using implementation types like ''{0}''; use the interface instead" name="LooseCoupling">
        <description>
Avoid using implementation types (i.e., HashSet); use the interface (i.e, Set) instead
      </description>
        <example><![CDATA[

import java.util.*;
public class Bar {
 // Use List instead
 private ArrayList list = new ArrayList();
 // Use Set instead
 public HashSet getFoo() {
  return new HashSet();
 }
}
  
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.optimization.LocalVariableCouldBeFinal" message="Local variable ''{0}'' could be declared final" name="LocalVariableCouldBeFinal">
        <description>
A local variable assigned only once can be declared final.
      </description>
        <example><![CDATA[
  
public class Bar {
 public void foo () {
  String a = "a"; //if a will not be assigned again it is better to do this:
  final String b = "b";
 }
}
  
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.optimization.MethodArgumentCouldBeFinal" message="Parameter ''{0}'' is not assigned and could be declared final" name="MethodArgumentCouldBeFinal">
        <description>
A method argument that is never assigned can be declared final.
      </description>
        <example><![CDATA[
  
public void foo (String param) {
  // do stuff with param never assigning it
  // better: public void foo (final String param) {
}
  
      ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.optimization.AvoidInstantiatingObjectsInLoops" message="Avoid instantiating new objects inside loops" name="AvoidInstantiatingObjectsInLoops">
        <description>
Detects when a new object is created inside a loop
    </description>
        <example><![CDATA[

public class Something {
  public static void main( String as[] ) {  
    for (int i = 0; i < 10; i++) {
      Foo f = new Foo(); //Avoid this whenever you can it's really expensive
    }
  }
}

    ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Use ArrayList instead of Vector" name="UseArrayListInsteadOfVector">
        <description>
ArrayList is a much better Collection implementation than Vector.
      </description>
        <example><![CDATA[

public class SimpleTest extends TestCase {
 public void testX() {
  Collection c = new Vector();
  // This achieves the same with much better performance
  // Collection c = new ArrayList();
 }
}

          ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//AllocationExpression
 /ClassOrInterfaceType[@Image='Vector' or @Image='java.util.Vector']

              ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="This call to String.startsWith can be rewritten using String.charAt(0)" name="SimplifyStartsWith">
        <description>
Since it passes in a literal of length 1, this call to String.startsWith can be rewritten using String.charAt(0) to save some time.
      </description>
        <example><![CDATA[
  
public class Foo {
  boolean checkIt(String x) {
      return x.startsWith("a");
  }
}

      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[

//PrimaryExpression
 [PrimaryPrefix/Name
  [ends-with(@Image, '.startsWith')]]
 [PrimarySuffix/Arguments/ArgumentList
  /Expression/PrimaryExpression/PrimaryPrefix
  /Literal
   [string-length(@Image)=3]
   [starts-with(@Image, '"')]
   [ends-with(@Image, '"')]
 ]
 
            ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.optimization.UseStringBufferForStringAppends" message="Prefer StringBuffer over += for concatenating strings" name="UseStringBufferForStringAppends">
        <description>
Finds usages of += for appending strings.
           </description>
        <example><![CDATA[
      
public class Foo {
 void bar() {
  String a;
  a = "foo";
  a += " bar";
  // better would be:
  // StringBuffer a = new StringBuffer("foo");
  // a.append(" bar);
 }
}
      
           ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Use asList instead of tight loops" name="UseArraysAsList">
        <description>
   The class java.util.Arrays has a "asList" method that
   should be use when you want to create a new List from
   an array of objects. It is faster than executing a loop to
   cpy all the elements of the array one by one
     </description>
        <example><![CDATA[
   
   public class Test {
    public void foo(Integer[] ints) {
    // could just use Arrays.asList(ints)
     List l= new ArrayList(10);
     for (int i=0; i< 100; i++) {
      l.add(ints[i]);
     }
     for (int i=0; i< 100; i++) {
      l.add(a[i].toString()); // won't trigger the rule
     }
    }
   }
   
     ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
   
//Statement[
    (ForStatement) and (count(.//IfStatement)=0)
   ]
   //StatementExpression[
    PrimaryExpression/PrimaryPrefix/Name[
	 substring-before(@Image,'.add') = ancestor::MethodDeclaration//LocalVariableDeclaration[
      ./Type//ClassOrInterfaceType[
       @Image = 'Collection' or 
       @Image = 'List' or @Image='ArrayList'
      ]
     ]
     /VariableDeclarator/VariableDeclaratorId[
      count(..//AllocationExpression/ClassOrInterfaceType[
       @Image="ArrayList"
      ]
      )=1
     ]/@Image
    ]
   and
   PrimaryExpression/PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix/Name
   [@Image = ancestor::MethodDeclaration//LocalVariableDeclaration
   [@Array="true"]/VariableDeclarator/VariableDeclaratorId/@Image]
   /../..[count(.//PrimarySuffix)
   =1]/PrimarySuffix/Expression/PrimaryExpression/PrimaryPrefix
   /Name
   ]
   
       ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="System.arraycopy is more efficient" name="AvoidArrayLoops">
        <description>
    Instead of copying data between two arrays, use
    System.arraycopy method
      </description>
        <example><![CDATA[
    
public class Test {
 public void bar() {
  int[] a = new int[10];
  int[] b = new int[10];
  for (int i=0;i<10;i++) {
   b[i]=a[i];
  }
 }
}
            // this will trigger the rule
            for (int i=0;i<10;i++) {
             b[i]=a[c[i]];
            }

        }
    }
    
      ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
    
//Statement[(ForStatement or WhileStatement) and
count(*//AssignmentOperator[@Image = '='])=1
and
*/Statement
[
./Block/BlockStatement/Statement/StatementExpression/PrimaryExpression
/PrimaryPrefix/Name/../../PrimarySuffix/Expression
[(PrimaryExpression or AdditiveExpression) and count
(.//PrimaryPrefix/Name)=1]//PrimaryPrefix/Name/@Image
and
./Block/BlockStatement/Statement/StatementExpression/Expression/PrimaryExpression
/PrimaryPrefix/Name/../../PrimarySuffix[count
(..//PrimarySuffix)=1]/Expression[(PrimaryExpression
or AdditiveExpression) and count(.//PrimaryPrefix/Name)=1]
//PrimaryPrefix/Name/@Image
]]
    
        ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.optimization.UnnecessaryWrapperObjectCreation" message="Unnecessary wrapper object creation" name="UnnecessaryWrapperObjectCreation">
        <description>
Parsing method should be called directy instead.
      </description>
        <example><![CDATA[

public int convert(String s) {
  int i, i2;

  i = Integer.valueOf(s).intValue(); // this wastes an object
  i = Integer.parseInt(s); // this is better

  i2 = Integer.valueOf(i).intValue(); // this wastes an object
  i2 = i; // this is better

  return i2;
}

          ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Do not add empty strings" name="AddEmptyString">
        <description>
Finds empty string literals which are being added. This is an inefficient way 
to convert any type to a String.
        </description>
        <example><![CDATA[
             
        String s = "" + 123; // bad 
        String t = Integer.toString(456); // ok 
            
        ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                     
//AdditiveExpression/PrimaryExpression/PrimaryPrefix/Literal[@Image='""']
                
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Object clone() should be implemented with super.clone()" name="ProperCloneImplementation">
        <description>
Object clone() should be implemented with super.clone().
     </description>
        <example><![CDATA[
 
class Foo{
    public Object clone(){
        return new Foo(); // This is bad
    }
}

     ]]></example>
        <priority>2</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                 
//MethodDeclarator
[@Image = 'clone']
[count(FormalParameters/*) = 0]
[count(../Block//*[
    (self::AllocationExpression) and
    (./ClassOrInterfaceType/@Image = ancestor::
ClassOrInterfaceDeclaration[1]/@Image)
  ])> 0
]
                
             ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="clone() method should throw CloneNotSupportedException" name="CloneThrowsCloneNotSupportedException">
        <description>
The method clone() should throw a CloneNotSupportedException.
         </description>
        <example><![CDATA[
             
 public class MyClass implements Cloneable{
     public Object clone() { // will cause an error
          MyClass clone = (MyClass)super.clone();
          return clone;
     }
 }
    
         ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                     
//MethodDeclaration
[
MethodDeclarator/@Image = 'clone'
and count(MethodDeclarator/FormalParameters/*) = 0
and count(NameList/Name[contains
(@Image,'CloneNotSupportedException')]) = 0
]
[
../../../../ClassOrInterfaceDeclaration[@Final = 'false']
]
                     
                 ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="clone() method should be implemented only if implementing Cloneable interface" name="CloneMethodMustImplementCloneable">
        <description>
The method clone() should only be implemented if the class implements the Cloneable interface with the exception of a final method that only throws CloneNotSupportedException.
        </description>
        <example><![CDATA[
            
public class MyClass {
 public Object clone() throws CloneNotSupportedException {
  return foo;
 }
}
   
        ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
                    
//ClassOrInterfaceDeclaration
[not(./ImplementsList/ClassOrInterfaceType
[@Image='Cloneable'])]
/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration
[MethodDeclaration
[MethodDeclarator[@Image
= 'clone' and count(FormalParameters/*) = 0]]
[not((../MethodDeclaration[@Final = 'true'] or ancestor::ClassOrInterfaceDeclaration[1][@Final = 'true'])
and Block[count(BlockStatement)=1]
/BlockStatement/Statement/ThrowStatement/Expression
/PrimaryExpression/PrimaryPrefix/AllocationExpression
/ClassOrInterfaceType[@Image = 'CloneNotSupportedException'])]]

                    
                ]]></value>
            </property>
        </properties>
    </rule>
    <rule class="net.sourceforge.pmd.rules.imports.DuplicateImportsRule" message="Avoid duplicate imports such as ''{0}''" name="DuplicateImports">
        <description>
    Avoid duplicate import statements.
    </description>
        <example><![CDATA[

import java.lang.String;
import java.lang.*;
public class Foo {}

    ]]></example>
        <priority>4</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.imports.DontImportJavaLang" message="Avoid importing anything from the package 'java.lang'" name="DontImportJavaLang">
        <description>
Avoid importing anything from the package 'java.lang'.  These classes are automatically imported (JLS 7.5.3).
    </description>
        <example><![CDATA[

// this is bad
import java.lang.String;
public class Foo {}

// --- in another source code file...

// this is bad
import java.lang.*;

public class Foo {}

    ]]></example>
        <priority>4</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.imports.UnusedImportsRule" message="Avoid unused imports such as ''{0}''" name="UnusedImports">
        <description>
    Avoid unused import statements.
    </description>
        <example><![CDATA[

// this is bad
import java.io.File;
public class Foo {}

    ]]></example>
        <priority>4</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.imports.ImportFromSamePackageRule" message="No need to import a type that lives in the same package" name="ImportFromSamePackage">
        <description>
 No need to import a type that lives in the same package.
     </description>
        <example><![CDATA[
 
 package foo;
 import foo.Buz; // no need for this
 import foo.*; // or this
 public class Bar{}
 
     ]]></example>
        <priority>3</priority>
        <properties/>
    </rule>
    <rule class="net.sourceforge.pmd.rules.XPathRule" message="Too many static imports may lead to messy code" name="TooManyStaticImports">
        <description>
If you overuse the static import feature, it can make your program unreadable and 
unmaintainable, polluting its namespace with all the static members you import. 
Readers of your code (including you, a few months after you wrote it) will not know 
which class a static member comes from (Sun 1.5 Language Guide).
		 </description>
        <example><![CDATA[
import static Lennon;
import static Ringo;
import static George;
import static Paul;
import static Yoko; // Too much !
		  ]]></example>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value><![CDATA[
.[count(ImportDeclaration[@Static = 'true']) > $maximumStaticImports]
	             ]]></value>
            </property>
            <property name="maximumStaticImports" value="4"/>
        </properties>
    </rule>
</ruleset>
