Skip to content

BigDecimalLiteralDouble false negative for the boxed value #5759

@Emilyaxe

Description

@Emilyaxe

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions