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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 14.0.1
    • Fix Version/s: 16
    • Component/s: core-libs
    • Subcomponent:
    • Resolved In Build:
      b10
    • Verification:
      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

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

                Dates

                Created:
                Updated:
                Resolved: