Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

“This code converts an integer value (e.g., int or long) to a double precision floating point number and then passes the result to the Math.ceil() function, which rounds a double to the next higher integer value. This operation is useless, since converting an integer to a double should give a number with no fractional part. It is likely that the operation that generated the value to be passed to Math.ceil was intended to be performed using double precision floating point arithmetic.” – 2013-11-24

The cast from an int to a double yields a double with no fractional part. Thus passing the resulting double to the Math.ceil() function makes no sense – ceiling such a value always yields the same number.

So the obvious treatments of this bug are

- to remove the Math.ceil() operation (by an automated fix) or
- to alert the developer that the original integer value might have better been generated by using double precision floating point arithmetic (manually).

<code Java> public void wrong1() {

int i = 1; Math.ceil((double) i); }

</Code>

<code Java> public void wrong2(int i) {

Math.ceil((double) i); }

</Code>

<code Java> public class IntValueMathCeil{

private int x = 0; public void wrong3() { int i = 10; x = Math.ceil((double) i); }

} </Code>

<code Java> public void wrong1() {

int i = 1; }

</Code>

<code Java> public class IntValueMathCeil{

private int x = 0; public void wrong3() { int i = 10; x = i; }

} </Code>

Benchmark project | Precision | Recall | ||||
---|---|---|---|---|---|---|

FB | JT | Delta | FB | JT | Delta | |

Project … | …% | …% | …% | …% | …% | …% |

Project … | …% | …% | …% | …% | …% | …% |

FB = FindBugs, JT = JTransformer, Delta = JTransformer - FindBugs

teaching/labs/mdse/2013/bug_descriptions/jt-bug-cor58.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2023