Buggy code:
public class UriComponentsBuilder { private static final Pattern QUERY_PARAM_PATTERN = Pattern . compile ( "([^&=]+)=?([^&=]+)?" ) ; 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 ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( "^(" + ( UriComponentsBuilder . SCHEME_PATTERN ) ) + ")?" ) + "(////(" ) + ( UriComponentsBuilder . USERINFO_PATTERN ) ) + "@)?" ) + ( UriComponentsBuilder . HOST_PATTERN ) ) + "(:" ) + ( UriComponentsBuilder . PORT_PATTERN ) ) + ")?" ) + ")?" ) + ( UriComponentsBuilder . PATH_PATTERN ) ) + "(\\?" ) + ( UriComponentsBuilder . QUERY_PATTERN ) ) + ")?" ) + "(#" ) + ( UriComponentsBuilder . LAST_PATTERN ) ) + ")?" ) ) ; private static final Pattern HTTP_URL_PATTERN = Pattern . compile ( ( ( ( ( ( ( ( ( ( ( ( ( ( "^" + ( UriComponentsBuilder . HTTP_PATTERN ) ) + "(////(" ) + ( UriComponentsBuilder . USERINFO_PATTERN ) ) + "@)?" ) + ( UriComponentsBuilder . HOST_PATTERN ) ) + "(:" ) + ( UriComponentsBuilder . PORT_PATTERN ) ) + ")?" ) + ")?" ) + ( UriComponentsBuilder . PATH_PATTERN ) ) + "(\\?" ) + ( UriComponentsBuilder . LAST_PATTERN ) ) + ")?" ) ) ; private String scheme ; private String userInfo ; private String host ; private int port = - 1 ; private UriComponentsBuilder . PathComponentBuilder pathBuilder = UriComponentsBuilder . NULL_PATH_COMPONENT_BUILDER ; private final MultiValueMap < String , String > queryParams = new org . springframework . util . LinkedMultiValueMap < String , String > ( ) ; private String fragment ; protected UriComponentsBuilder ( ) { } public static UriComponentsBuilder newInstance ( ) { } public static UriComponentsBuilder fromPath ( String path ) { } public static UriComponentsBuilder fromUri ( URI uri ) { } public static UriComponentsBuilder fromUriString ( String uri ) { } public static UriComponentsBuilder fromHttpUrl ( String httpUrl ) { } public UriComponents build ( ) { } public UriComponents build ( boolean encoded ) { <START_BUG> return new UriComponents ( scheme , userInfo , host , port , pathBuilder . build ( ) , queryParams , fragment , encoded ) ; <END_BUG> } public UriComponentsBuilder uri ( URI uri ) { } public UriComponentsBuilder scheme ( String scheme ) { } public UriComponentsBuilder userInfo ( String userInfo ) { } public UriComponentsBuilder host ( String host ) { } public UriComponentsBuilder port ( int port ) { } public UriComponentsBuilder path ( String path ) { } public UriComponentsBuilder pathSegment ( String ... pathSegments ) throws IllegalArgumentException { } public UriComponentsBuilder query ( String query ) { } public UriComponentsBuilder queryParam ( String name , Object ... values ) { } public UriComponentsBuilder fragment ( String fragment ) { } private interface PathComponentBuilder { PathComponent build ( ) { } UriComponentsBuilder . PathComponentBuilder appendPath ( String path ) { } UriComponentsBuilder . PathComponentBuilder appendPathSegments ( String ... pathSegments ) { } } private static class FullPathComponentBuilder implements UriComponentsBuilder . PathComponentBuilder { private final StringBuilder path ; private FullPathComponentBuilder ( String path ) { } public PathComponent build ( ) { } public UriComponentsBuilder . PathComponentBuilder appendPath ( String path ) { } public UriComponentsBuilder . PathComponentBuilder appendPathSegments ( String ... pathSegments ) { } } private static class PathSegmentComponentBuilder implements UriComponentsBuilder . PathComponentBuilder { private final List < String > pathSegments = new ArrayList < String > ( ) ; private PathSegmentComponentBuilder ( String ... pathSegments ) { } public PathComponent build ( ) { } public UriComponentsBuilder . PathComponentBuilder appendPath ( String path ) { } public UriComponentsBuilder . PathComponentBuilder appendPathSegments ( String ... pathSegments ) { } } private static class PathComponentCompositeBuilder implements UriComponentsBuilder . PathComponentBuilder { private final List < UriComponentsBuilder . PathComponentBuilder > pathComponentBuilders = new ArrayList < UriComponentsBuilder . PathComponentBuilder > ( ) ; private PathComponentCompositeBuilder ( UriComponentsBuilder . PathComponentBuilder builder ) { } public PathComponent build ( ) { } public UriComponentsBuilder . PathComponentBuilder appendPath ( String path ) { } public UriComponentsBuilder . PathComponentBuilder appendPathSegments ( String ... pathSegments ) { } } private static UriComponentsBuilder . PathComponentBuilder NULL_PATH_COMPONENT_BUILDER = new UriComponentsBuilder . PathComponentBuilder ( ) { public PathComponent build ( ) { } public UriComponentsBuilder . PathComponentBuilder appendPath ( String path ) { } public UriComponentsBuilder . PathComponentBuilder appendPathSegments ( String ... pathSegments ) { } } ; }

Fix:
return new UriComponents ( scheme , userInfo , host , port , pathBuilder . build ( ) , queryParams , fragment , encoded , true ) ;