RFR: 8332686: InetAddress.ofLiteral can throw StringIndexOutOfBoundsException

Daniel Fuchs dfuchs at openjdk.org
Tue Dec 3 17:14:38 UTC 2024


On Tue, 3 Dec 2024 15:52:31 GMT, Aleksei Efimov <aefimov at openjdk.org> wrote:

> The proposed change fixes `InetAddress.ofLiteral` and `Inet6Address.ofLiteral` to throw `IllegalArgumentException` instead of `StringIndexOutOfBoundsException` when an empty IP addres literal string is specified.   
> The `Inet4Address.ofLiteral` correctly throws `IllegalArgumentException` when a literal cannot be parsed as an IPv4 address literal. It was addressed before in [JDK-8315767](https://bugs.openjdk.org/browse/JDK-8315767) fix.
> 
> Testing: the modified `OfLiteralTest` test and other tests from `jdk-tier1` to `jdk-tier3` tiers

Looks fine but you could additionally add this in InetAddress::ofLiteral:


      public static InetAddress ofLiteral(String ipAddressLiteral) {
          Objects.requireNonNull(ipAddressLiteral);
+         if (ipAddressLiteral.isEmpty()) {
+              throw IPAddressUtil.invalidIpAddressLiteral(ipAddressLiteral);
+         }

-------------

PR Comment: https://git.openjdk.org/jdk/pull/22518#issuecomment-2515136525


More information about the net-dev mailing list