`BigDecimalLiteralDouble ` false negative for the boxed value
Error Prone version
2.49.0 (error_prone_core)
Check name
BigDecimalLiteralDouble
Description
The check reports new BigDecimal(double) and new BigDecimal(float) for primitive arguments, but misses the same constructions when the value is wrapped in Double or Float. Since BigDecimal has no Double/Float constructor, the boxed value is automatically unboxed and the same lossy conversion still occurs. This causes a false negative for the boxed forms.
Reproducer
import java.math.BigDecimal;
class Repro {
// BEFORE — correctly flagged
BigDecimal a = new BigDecimal(0.1);
BigDecimal b = new BigDecimal(0.3f);
BigDecimal c;
{
float f = 0.1f;
c = new BigDecimal(f);
}
// AFTER — not flagged, but semantically identical (auto-unboxing)
Double boxedD = 0.1;
BigDecimal a2 = new BigDecimal(boxedD);
BigDecimal b2 = new BigDecimal((Float) 0.3f);
Float boxedF = 0.1f;
BigDecimal c2 = new BigDecimal(boxedF);
}
Actual behavior
Only the BEFORE primitive-literal constructions are flagged; every boxed form — variable-typed, cast, or initialized from a literal — passes without a warning.
Hi, I would like to work on this issue.
My plan is to add regression coverage for boxed Double/Float values that are auto-unboxed when passed to BigDecimal(double), then update BigDecimalLiteralDouble to detect those cases consistently with primitive floating-point literals.