[External] : RFD: URLs with empty host component but non-empty ports
Eirik Bjørsnøs
eirbjo at gmail.com
Thu Feb 26 10:36:14 UTC 2026
Hi,
Consider the following:
URL url = new URL("http", "", 80, "/image.gif", null);
String authority = url.getAuthority();
int port = url.getPort();
The authority here ends up as ":80" and the port as 80, the full string
representation "http://:80/image.gif".
Note that if we pass null instead of the empty string for host, we end up
with a URL with a null authority and a -1 port. The URL string will be
"http:/image.gif".
Two things stand out from this observation:
1: This URL constructor treats null and empty string differently,
which seems strange
2: When passing the empty host component and a port != -1, the resulting
URL has a server-based authority component without any host part, which
seems strange
Is there a way out of this situation?
Eirik.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/net-dev/attachments/20260226/112dbfa8/attachment.htm>
More information about the net-dev
mailing list