According to rain.drop in kakaopay, it appears that UriComponentsBuilder#fromUri has a bug where it fails to recognize hostnames containing underscores (_) due to a limitation of java.net.URI. In contrast, UriComponentsBuilder#fromUriString successfully parses these hostnames using URI_PATTERN.

For example, UriComponentsBuilder.fromUri(URI("kakaopay://payweb_tab")) results in a null host but payweb_tab becomes its authority, unlike UriComponentsBuilder.fromUriString("kakaopay://payweb_tab") says its host and authority are both payweb_tab.

This issue arises because java.net.URI adheres to RFC 2396 and RFC 2732 but does not conform to RFC 3986, which allows underscores in hostnames as per the URI_PATTERN. This inconsistency can lead to problems when parsing such URIs with the standard URI class, potentially resulting in the getHost() method returning null.

https://github.com/openjdk/jdk/blob/ae4d2f15901bf02efceaac26ee4aa3ae666bf467/src/java.base/share/classes/java/net/URI.java#L3513-L3520

Comment From: pivotal-cla

@yhkee0404 Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-cla

@yhkee0404 Thank you for signing the Contributor License Agreement!

Comment From: bclozel

Thanks for the proposal, but I don't think we should add a special case for this; java.net.URI has a specific behavior and we should not change it because it would create inconsistencies. fromUriString uses a different parsing algorithm. We will refine our documentation and stance on this matter in #33542