`BigDecimalLiteralDouble ` false negative for the boxed value
- Dominant language
- Java
- Stars
- 7.2k
- Forks
- 820
- Avg merge
- 5h 9m
- Merged PRs (30d)
- 50
Description
### 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
```java
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.
Contributor guide
Assessment
This issue has not been assessed yet.