JDK-8030814 : Long.parseUnsignedLong should throw exception on too large input
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-12-19
  • Updated: 2015-04-13
  • Resolved: 2014-01-15
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 9
9 b02Fixed
Related Reports
Duplicate :  
Relates :  
Description
The Javadoc of Long.parseUnsignedLong specifies that it should throw a
NumberFormatException if "the value represented by the string is larger
than the largest unsigned long, 2^64-1."

Test:

import java.math.BigInteger;

public class UnsignedLongBug {
  public static void main(String[] args) {
    try {
      String input = "1234567890abcdef1";
      System.out.println(Long.parseUnsignedLong(input, 16));
      BigInteger maxUnsignedLong =
BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE);
      BigInteger inputValue = new BigInteger(input, 16);
      System.out.println(maxUnsignedLong.compareTo(inputValue));
      throw new AssertionError();
    } catch (NumberFormatException expected) {
      System.out.println("Correct");
    }
  }
}


Found by:  Louis Wasserman <lowasser@google.com>
Comments
core-libs-dev thread: http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-December/024031.html
19-12-2013