JDK-8021204 : Constructor BigInteger(String val, int radix) doesn't detect overflow
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.math
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: linux_ubuntu
  • Submitted: 2013-07-23
  • Updated: 2014-01-06
  • Resolved: 2013-10-31
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b115Fixed
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version  " 1.8.0-ea " 
Java(TM) SE Runtime Environment (build 1.8.0-ea-b99)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b41, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux kisa 3.8.0-26-generic #38-Ubuntu SMP Mon Jun 17 21:43:33 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
Constructors BigInteger(String val, int radix) and BigInteger(String val) doesn't detect that value of val is out of supported range. They may consume long string silently and construct BigInteger object with incorrect value.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run and compile the attached test

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Constructor throws ArithmeticException
ACTUAL -
bi=1


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.math.BigInteger;

public class BigIntegerStringConstructorTest {
    
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder();
        sb.append('1');
        for (int i = 0; i < (1 << 30) - 1; i++) {
            sb.append('0');
        }
        sb.append('1');
        String s = sb.toString();
        sb = null;
        BigInteger bi = new BigInteger(s, 16);
        System.out.println( " bi= "  + bi);
    }
}

---------- END SOURCE ----------