8200659: Improve BigDecimal support

Reviewed-by: darcy, rhalade, mschoene
This commit is contained in:
Brian Burkhalter 2018-08-22 15:55:04 -07:00
parent d2590ffc9d
commit 8f14f8b2a7
5 changed files with 388 additions and 44 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -31,6 +31,7 @@ package java.math;
import static java.math.BigInteger.LONG_MASK;
import java.util.Arrays;
import java.util.Objects;
/**
* Immutable, arbitrary-precision signed decimal numbers. A
@ -424,9 +425,14 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
* @since 1.5
*/
public BigDecimal(char[] in, int offset, int len, MathContext mc) {
// protect against huge length.
if (offset + len > in.length || offset < 0)
throw new NumberFormatException("Bad offset or len arguments for char[] input.");
// protect against huge length, negative values, and integer overflow
try {
Objects.checkFromIndexSize(offset, len, in.length);
} catch (IndexOutOfBoundsException e) {
throw new NumberFormatException
("Bad offset or len arguments for char[] input.");
}
// This is the primary string to BigDecimal constructor; all
// incoming strings end up here; it uses explicit (inline)
// parsing for speed and generates at most one intermediate