AppPerfect

Java 64-BITS coding

Rules available in this category:

  1. Avoid_shift_operators
  2. Invalid_shift_operand
  3. Avoid_unnecessary_unsigned_right_shift

Rule 1: Avoid_shift_operators

Severity:  Medium
Rule:  Use of shift operator may produce undesire result when application is run in machine with different word size
Reason:  Use of shift operator may produce undesire result when application is run in machine with different word size

Usage Example: 

package com.rule;
class Avoid_shift_operators_violation
{
public void method()
{
int x = 0;
int X = x >> 2; // VIOLATION
int Y = x << 1; // VIOLATION
X++;
Y++;
}
}

Should be written as:

package com.rule;
class Avoid_shift_operators_correction
{
public void method()
{
int x = 0;
int X = x / 4; // CORRECTION
int Y = x * 2; // CORRECTION
X++;
Y++;
}
}

Reference:  Reference Not Available.

Rule 2: Invalid_shift_operand

Severity:  Medium
Rule:  Avoid using invalid operand in shift operation.
Reason:  Avoid using invalid operand in shift operation.

Usage Example: 

package com.rule;

public class Invalid_shift_operand_violation
{
public void method()
{
int i = 10;

i = i << 32; // Vioalation
}

}

Should be written as:

package com.rule;

public class Invalid_shift_operand_correction
{
public void method()
{
int i = 10;

i = i << 2; // Correction
}

}

Reference:  Reference not available.

Rule 3: Avoid_unnecessary_unsigned_right_shift

Severity:  Medium
Rule:  Avoid unnecessary unsigned right shift.
Reason:  Avoid unnecessary unsigned right shift.

Usage Example: 

package com.rule;

public class Avoid_unnecessary_unsigned_right_shift_violation
{
public void method()
{
int i = 10;

Short s = (short)( i >>> 2 ); // Violation.
}

}

Should be written as:

package com.rule;

public class Avoid_unnecessary_unsigned_right_shift_correction
{
public void method()
{
int i = 10;

Short s = (short)( i >> 2 ); // Correction.
}

}

Reference:  Reference not available.

We use cookies for analytics, advertising and to improve our site. By continuing to use our site, you accept to our Privacy policy and allow us to store cookies.