Double.longBitsToDouble gets a 32-bit value, which it widens before decoding

tx0/java:int-bits-to-doubledefaultwarningbug

What it finds

Double.longBitsToDouble(bits) with an int widens the int to a long first, with its sign extended: the upper 32 bits are all zeros or all ones, and the result is a tiny subnormal number or NaN, never the value the bits were meant to encode. A float in 32 bits is decoded with Float.intBitsToFloat.

From the rule's source, int_bits_to_double.rs.

Example from the rule's tests
class Bits {  double decode(int raw, long wide) {    double a = Double.longBitsToDouble(raw);tx0 reports: raw has only 32 bits    double b = Double.longBitsToDouble(wide);    return a + b;  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/java:int-bits-to-double" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:int-bits-to-double] reason="..."

tx0 explain tx0/java:int-bits-to-double shows the same in the terminal. Found a false positive? Report it.