PB.CLP
Don't cast primitive datatypes to lower precision
Description
This rule flags any primitive datatype that is cast to lower precision.
By casting to lower precision, the value is truncated and will fall into a different range.
Example
package PB;
public class CLP {
void method () {
double d = 4.25;
int i;
i = this.square ((int) d);
}
int square (int i) {
return (i * i);
}
}
Repair
Either explicitly test the value before performing a cast or avoid it.
|