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

InetAddress.ofLiteral can throw StringIndexOutOfBoundsException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • 22.0.1
    • core-libs
    • None
    • b27

      java.net.Inet6Address.ofLiteral(" ")

      throws

      | Exception java.lang.IllegalArgumentException: Invalid IP address literal:

      which is expected, however passing an empty string throws an SIOOBE:

      jshell> java.net.Inet6Address.ofLiteral("")
      | Exception java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
      | at Preconditions$1.apply (Preconditions.java:55)
      | at Preconditions$1.apply (Preconditions.java:52)
      | at Preconditions$4.apply (Preconditions.java:213)
      | at Preconditions$4.apply (Preconditions.java:210)
      | at Preconditions.outOfBounds (Preconditions.java:98)
      | at Preconditions.outOfBoundsCheckIndex (Preconditions.java:106)
      | at Preconditions.checkIndex (Preconditions.java:302)
      | at String.checkIndex (String.java:4930)
      | at StringLatin1.charAt (StringLatin1.java:46)
      | at String.charAt (String.java:1629)
      | at Inet6Address.parseAddressString (Inet6Address.java:558)
      | at Inet6Address.ofLiteral (Inet6Address.java:526)
      | at (#1:1)


      and

      jshell> java.net.Inet4Address.ofLiteral("")
      | Exception java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
      | at Preconditions$1.apply (Preconditions.java:55)
      | at Preconditions$1.apply (Preconditions.java:52)
      | at Preconditions$4.apply (Preconditions.java:213)
      | at Preconditions$4.apply (Preconditions.java:210)
      | at Preconditions.outOfBounds (Preconditions.java:98)
      | at Preconditions.outOfBoundsCheckIndex (Preconditions.java:106)
      | at Preconditions.checkIndex (Preconditions.java:302)
      | at String.checkIndex (String.java:4930)
      | at StringLatin1.charAt (StringLatin1.java:46)
      | at String.charAt (String.java:1629)
      | at IPAddressUtil.isBsdParsableV4 (IPAddressUtil.java:669)
      | at IPAddressUtil.validateNumericFormatV4 (IPAddressUtil.java:153)
      | at Inet4Address.parseAddressString (Inet4Address.java:208)
      | at Inet4Address.ofLiteral (Inet4Address.java:180)
      | at (#2:1)

            aefimov Aleksej Efimov
            mschoene Marc Schönefeld
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: