Index: math/src/test/java/tests/api/java/math/BigDecimalTest.java =================================================================== --- math/src/test/java/tests/api/java/math/BigDecimalTest.java (revision 396853) +++ math/src/test/java/tests/api/java/math/BigDecimalTest.java (working copy) @@ -135,6 +135,23 @@ } catch (NumberFormatException e) { } } + + /** + * @tests java.math.BigDecimal#BigDecimal(char[]) + */ + public void test_constructor_CC_plus_minus_exp() { + try { + new BigDecimal("+35e+-2".toCharArray()); + fail("NumberFormatException expected"); + } catch (NumberFormatException e) { + } + + try { + new BigDecimal("-35e-+2".toCharArray()); + fail("NumberFormatException expected"); + } catch (NumberFormatException e) { + } + } /** * @tests java.math.BigDecimal#abs() Index: math/src/main/java/java/math/BigInteger.java =================================================================== --- math/src/main/java/java/math/BigInteger.java (revision 396856) +++ math/src/main/java/java/math/BigInteger.java (working copy) @@ -67,26 +67,6 @@ /** * @com.intel.drl.spec_ref */ - private int bitCount = -1; - - /** - * @com.intel.drl.spec_ref - */ - private int bitLength = -1; - - /** - * @com.intel.drl.spec_ref - */ - private int lowestSetBit = -2; - - /** - * @com.intel.drl.spec_ref - */ - private int firstNonzeroByteNum = -2; - - /** - * @com.intel.drl.spec_ref - */ private byte[] magnitude; /** @@ -423,18 +403,6 @@ } /** - * Counts the bit length of an unsigned int value - */ - private static int getBitLength(int value) { - int bitLen = 32; - int topOne = 0x80000000; - while (((value & topOne) == 0) && bitLen-- > 0) { - topOne >>>= 1; - } - return bitLen; - } - - /** * Gets the number of radix-based digits that fits in an integer * @param radix the radix of the numerical system * @return the number of digits @@ -730,7 +698,7 @@ if (numberBitLength < 0) { throw new IllegalArgumentException("negative bit length"); } - boolean stripLeadingZeroes = true; + boolean stripLeadingZeroes = numberBitLength > 0; constructRandomly(numberBitLength, rand, stripLeadingZeroes); } @@ -1173,6 +1141,9 @@ */ public int compareTo(BigInteger that) { if (this.sign == that.sign) { + if(this.sign == 0) { + return 0; + } int compareResult = compareMagnitude(this.digits, this.numberLength, that.digits, that.numberLength); if (this.sign == 1) { @@ -1194,7 +1165,7 @@ */ private void constructRandomly(int numberBitLength, Random rand, boolean stripLeadingZeroes) { - sign = 1; + sign = numberBitLength == 0 ? 0 : 1; int numberOfDigits = numberBitLength >> 5; int numberOfTopBits = numberBitLength & 31; if (numberOfTopBits > 0) { @@ -1207,7 +1178,6 @@ } if (numberOfTopBits > 0) { digits[numberLength - 1] &= ((1 << numberOfTopBits) - 1); - int q = numberLength - 1; } if (stripLeadingZeroes) { cutOffLeadingZeroes(); Index: math/src/main/java/java/math/BigDecimal.java =================================================================== --- math/src/main/java/java/math/BigDecimal.java (revision 396822) +++ math/src/main/java/java/math/BigDecimal.java (working copy) @@ -266,6 +266,10 @@ } if (symbol == '+') { count++; + symbol = in[count]; + if(symbol == '-') { + throw new NumberFormatException("exponent is not signed integer"); + } } exponent = new String(in, count, endIndex - count + 1); int exp = 0; @@ -408,6 +412,10 @@ int strLen = value.length(); String unscaled; String exponent; + + if(strLen == 0) { + throw new NumberFormatException("empty string"); + } char symbol = value.charAt(0); int startPoint = symbol == '+' ? 1 : 0; @@ -442,6 +450,10 @@ } if (symbol == '+') { count++; + symbol = value.charAt(count); + if(symbol == '-') { + throw new NumberFormatException("exponent is not signed integer"); + } } exponent = value.substring(count, strLen); int exp = 0; @@ -1323,11 +1335,11 @@ boolean negNumber = intVal.signum() < 0; int startPoint = negNumber ? 2 : 1; int endPoint = intString.length(); - int exponent = -scale + intString.length() - (negNumber ? 2 : 1); + int exponent = -scale + intString.length() - startPoint; StringBuffer result = new StringBuffer(intString); if (scale > 0 && exponent >= -6) { if (exponent >= 0) { - result.insert(exponent + (negNumber ? 2 : 1), '.'); + result.insert(exponent + startPoint, '.'); } else { char zeros[] = new char[-exponent + 1]; zeros[0] = '0'; @@ -1384,12 +1396,12 @@ boolean negNumber = intVal.signum() < 0; int startPoint = negNumber ? 2 : 1; int endPoint = intString.length(); - int dotPosition = -scale + intString.length() - (negNumber ? 2 : 1); + int dotPosition = -scale + intString.length() - startPoint; StringBuffer result = new StringBuffer(intString); char zeros[]; if (scale > 0) { if (dotPosition >= 0) { - result.insert(dotPosition + (negNumber ? 2 : 1), '.'); + result.insert(dotPosition + startPoint, '.'); } else { zeros = new char[-dotPosition + 1]; zeros[0] = '0';