Jtest logo




Contents  Previous  Next  Index

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.


Contents  Previous  Next  Index

ParaSoft logo
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft