Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8077600

Long.parseUnsignedLong doesn't check for numeric overflow properly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8u40
    • core-libs
    • x86_64
    • linux

      FULL PRODUCT VERSION :
      openjdk version "1.8.0_40-internal"
      OpenJDK Runtime Environment (build 1.8.0_40-internal-b27)
      OpenJDK 64-Bit Server VM (build 25.40-b25, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      According to the documentation, java.lang.Long.parseUnsignedLong static method is supposed to throw NumberFormatException on strings representing values greater than 2**64-1. However, sometimes numeric overflow is not detected. Example:

      Long.parseUnsignedLong("46116860184273879040")

      On my machine, this expression is evaluated without throwing any exceptions, and the result is -9223372036854775808L (which is equal to 9223372036854775808 when interpreted as unsigned).
      Expected behavior: evaluation of this expression should result in NumberFormatException being thrown.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Test {
      public static void main(String[] args) {
      System.out.println(Long.toUnsignedString(Long.parseUnsignedLong("46116860184273879040")));
      }
      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: