Buggy code:
public abstract class UriUtils { private static final String SCHEME_PATTERN = "([^://?#]+):" ; private static final String HTTP_PATTERN = "(http|https):" ; private static final String USERINFO_PATTERN = "([^@//]*)" ; private static final String HOST_PATTERN = "([^//?#:]*)" ; private static final String PORT_PATTERN = "(\\d*)" ; private static final String PATH_PATTERN = "([^?#]*)" ; private static final String QUERY_PATTERN = "([^#]*)" ; private static final String LAST_PATTERN = "(.*)" ; private static final Pattern URI_PATTERN = Pattern . compile ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( "^(" + ( UriUtils . SCHEME_PATTERN ) ) + ")?" ) + "(////(" ) + ( UriUtils . USERINFO_PATTERN ) ) + "@)?" ) + ( UriUtils . HOST_PATTERN ) ) + "(:" ) + ( UriUtils . PORT_PATTERN ) ) + ")?" ) + ")?" ) + ( UriUtils . PATH_PATTERN ) ) + "(\\?" ) + ( UriUtils . QUERY_PATTERN ) ) + ")?" ) + "(#" ) + ( UriUtils . LAST_PATTERN ) ) + ")?" ) ) ; private static final Pattern HTTP_URL_PATTERN = Pattern . compile ( ( ( ( ( ( ( ( ( ( ( ( ( ( "^" + ( UriUtils . HTTP_PATTERN ) ) + "(////(" ) + ( UriUtils . USERINFO_PATTERN ) ) + "@)?" ) + ( UriUtils . HOST_PATTERN ) ) + "(:" ) + ( UriUtils . PORT_PATTERN ) ) + ")?" ) + ")?" ) + ( UriUtils . PATH_PATTERN ) ) + "(\\?" ) + ( UriUtils . LAST_PATTERN ) ) + ")?" ) ) ; @ Deprecated public static String encodeUri ( String uri , String encoding ) throws UnsupportedEncodingException { } @ Deprecated public static String encodeHttpUrl ( String httpUrl , String encoding ) throws UnsupportedEncodingException { } @ Deprecated public static String encodeUriComponents ( String scheme , String authority , String userInfo , String host , String port , String path , String query , String fragment , String encoding ) throws UnsupportedEncodingException { } public static String encodeScheme ( String scheme , String encoding ) throws UnsupportedEncodingException { } public static String encodeAuthority ( String authority , String encoding ) throws UnsupportedEncodingException { } public static String encodeUserInfo ( String userInfo , String encoding ) throws UnsupportedEncodingException { } public static String encodeHost ( String host , String encoding ) throws UnsupportedEncodingException { <START_BUG> return HierarchicalUriComponents . encodeUriComponent ( host , encoding , HOST_IPV4 ) ; <END_BUG> } public static String encodePort ( String port , String encoding ) throws UnsupportedEncodingException { } public static String encodePath ( String path , String encoding ) throws UnsupportedEncodingException { } public static String encodePathSegment ( String segment , String encoding ) throws UnsupportedEncodingException { } public static String encodeQuery ( String query , String encoding ) throws UnsupportedEncodingException { } public static String encodeQueryParam ( String queryParam , String encoding ) throws UnsupportedEncodingException { } public static String encodeFragment ( String fragment , String encoding ) throws UnsupportedEncodingException { } public static String decode ( String source , String encoding ) throws UnsupportedEncodingException { } }

Fix:
return HierarchicalUriComponents . encodeUriComponent ( host , encoding , HOST ) ;