RFR: 8349705: java.net.URI.scanIPv4Address throws unnecessary URISyntaxException

Daniel Fuchs dfuchs at openjdk.org
Mon Feb 10 10:52:14 UTC 2025


On Mon, 10 Feb 2025 08:47:36 GMT, Xiaolong Peng <xpeng at openjdk.org> wrote:

> java.net.URI.scanIPv4Address is a private method, it is only called by java.net.URI.takeIPv4Address and java.net.URI.parseIPv4Address, the URISyntaxException("Malformed IPv4 address") is not necessary, returning -1 should be good. In one of our systems, we noticed the exception consumes ~0.3% CPU.
> 
> Additional test:
> - [x] make test TEST=jdk/java/net

Changes requested by dfuchs (Reviewer).

src/java.base/share/classes/java/net/URI.java line 3469:

> 3467:                 return q;
> 3468:             }
> 3469:             fail("Malformed IPv4 address", q);

I am a bit uncomfortable with this change. I notice that the caller happens to catch the exception and return -1 only in the case where strict == false; In order to minimize the behavior changes suggest to do instead:

if (strict) fail("Malformed IPv4 address", q);

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

PR Review: https://git.openjdk.org/jdk/pull/23538#pullrequestreview-2605379524
PR Review Comment: https://git.openjdk.org/jdk/pull/23538#discussion_r1948828533


More information about the net-dev mailing list