I have a URI, http://my-host.1domain:1234/path, that throws a URISyntaxException using one URI constructor:
new URI("http", /*userInfo*/null, /*host*/"my-host.1domain", 1234, "/path", /*query*/null, /*fragment*/null);
Exception in thread "main" java.net.URISyntaxException: Illegal character in hostname at index 15: http://my-host.1domain:1234/path
at java.base/java.net.URI$Parser.fail(URI.java:2974)
at java.base/java.net.URI$Parser.parseHostname(URI.java:3517)
at java.base/java.net.URI$Parser.parseServer(URI.java:3358)
at java.base/java.net.URI$Parser.parseAuthority(URI.java:3277)
at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3219)
at java.base/java.net.URI$Parser.parse(URI.java:3175)
at java.base/java.net.URI.<init>(URI.java:708)
but parses correctly using a different URI constructor:
// parses correctly
new URI("http", /*authority*/"my-host.1domain:1234", "/path", /*query*/null, /*fragment*/null);
Tested in OpenJDK 17.0.1. I've checked that domain names can start with a digit. So am I misusing the URI constructor or is this a bug?
(Background: the failing constructor is called from UriComponentsBuilder in Spring Web, who closed this as not-a-bug in their code)