Migration Rules

Contains rules about migrating from one JDK version to another. Don't use these rules directly, rather, use a wrapper ruleset such as migrating_to_13.xml.

ReplaceVectorWithList

Consider replacing this Vector with the newer java.util.List

This rule is defined by the following XPath expression:


//Type/ReferenceType/ClassOrInterfaceType[@Image='Vector']
 
    

Here's an example of code that would trigger this rule:

			

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

  
		

ReplaceHashtableWithMap

Consider replacing this Hashtable with the newer java.util.Map

This rule is defined by the following XPath expression:

    
    //Type/ReferenceType/ClassOrInterfaceType[@Image='Hashtable']
     
        

Here's an example of code that would trigger this rule:

			
    
    public class Foo {
     void bar() {
        Hashtable h = new Hashtable();
     }
    }
    
      
		

ReplaceEnumerationWithIterator

Consider replacing this Enumeration with the newer java.util.Iterator

This rule is defined by the following XPath expression:

    
    //ImplementsList/ClassOrInterfaceType[@Image='Enumeration']
     
        

Here's an example of code that would trigger this rule:

			
    
public class Foo implements Enumeration {
    private int x = 42;
    public boolean hasMoreElements() {
        return true;
    }
    public Object nextElement() {
        return String.valueOf(i++);
    }
}
    
      
		

AvoidEnumAsIdentifier

Finds all places 'enum' is used as an identifier is used

This rule is defined by the following XPath expression:

                  
                    //VariableDeclaratorId[@Image='enum']
                  
              

Here's an example of code that would trigger this rule:

			
  
    public class A {
        public  class foo {
            String enum = "foo";
        }
    }
  
      
		

AvoidAssertAsIdentifier

Finds all places 'assert' is used as an identifier is used

This rule is defined by the following XPath expression:

                  
                    //VariableDeclaratorId[@Image='assert']
                  
              

Here's an example of code that would trigger this rule:

			
  
    public class A {
        public  class foo {
            String assert = "foo";
        }
    }
  
      
		

IntegerInstantiation

In JDK 1.5, calling new Integer() causes memory allocation. Integer.valueOf() is more memory friendly.

This rule is defined by the following XPath expression:

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

Here's an example of code that would trigger this rule:

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