Affects: spring-web 5.3.13


spring-web UriComponentsBuilder cannot parse a URI such as http://my-host.1domain:1234/path because the domain starts with a digit:

URI uri = new URI("http", "my-host.1domain:1234", "/path", null, null);
System.out.println(uri); // parses correctly

UriComponentsBuilder.fromUriString("http://my-host.1domain:1234/path")
    .build()
    .toUri();
java.lang.IllegalStateException: Could not create URI object: Illegal character in hostname at index 15: http://my-host.1domain:1234/path
    at org.springframework.web.util.HierarchicalUriComponents.toUri(HierarchicalUriComponents.java:521)
    at com.thefloow.ephemeral.Cheese.main(Cheese.java:12)
Caused by: 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)
    at org.springframework.web.util.HierarchicalUriComponents.toUri(HierarchicalUriComponents.java:517)
    ... 1 more

Comment From: poutsma

The core exception is from java.net.URI, so it seems to be a Java issue. It can be reproduced without Spring code:

URI uri = new URI("http", null, "my-host.1domain", 1234, "/path", null, null);

Interestingly, the following result prints null, which does not seem correct either:

System.out.println(new URI("http", "my-host.1domain:1234", "/path", null, null).getHost());

Comment From: poutsma

Resolving as invalid, as this is not a Spring bug.

Comment From: hertzsprung

Thanks for triaging so quickly. I've asked a StackOverflow question. The root cause looks like a bug/shortcoming in java.net.URI.