I am interested in two problems that occur frequently when moving code to 64 bits:
public class Test {
public static void main( String arg[] ) { long a = <some value>; int i = 0; i += a; for( i = 0; i < a; i++ ) System.err.println( i ); }
}
In this class, two problems arise: i+=a could cause an overflow, but will give no error or warning. Then the loop will exit when i becomes negative (instead when i == a).
Would be PMD able to spot such potential bugs with proper rules? thanks!