RFR: 8332686: InetAddress.ofLiteral can throw StringIndexOutOfBoundsException

Jaikiran Pai jpai at openjdk.org
Tue Dec 3 16:32:41 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

test/jdk/java/net/InetAddress/OfLiteralTest.java line 381:

> 379:                 Arguments.of(InetAddressClass.INET_ADDRESS, ""),
> 380:                 Arguments.of(InetAddressClass.INET4_ADDRESS, ""),
> 381:                 Arguments.of(InetAddressClass.INET6_ADDRESS, "")

Hello Aleksei, could we also add a "blank" literals in this test? Something like `Arguments.of(..., "     ")`? A quick test against current mainline shows that these implementation correctly throw an `IllegalArgumentException` for such strings. I think it would be good to have test coverage for those if we don't already do.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22518#discussion_r1868042538


More information about the net-dev mailing list