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

Documentation of BigInteger(String) constructor does not mention leading plus

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • P4
    • Resolution: Fixed
    • 14.0.1
    • 16
    • core-libs
    • b10
    • Verified

    Description

      A DESCRIPTION OF THE PROBLEM :
      The documentation for the BigInteger(String) constructor says:
      > The String representation consists of an optional minus sign followed by a sequence of one or more decimal digits.
      https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/math/BigInteger.html#%3Cinit%3E(java.lang.String)

      However, it actually accepts not only a leading minus sign ('-') but also a leading plus sign ('+'). This is likely an oversight in the documentation because the BigInteger(String, int) constructor (to which the constructor delegates) explicitly mentions the leading plus sign.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Since "+5" is parsed successfully, the documentation should specify that a leading plus sign is allowed as well.

      ---------- BEGIN SOURCE ----------
      new BigInteger("+5")
      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              darcy Joe Darcy
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: