code: public URI uri() {
          String uri = newBuilder().reencodeForUri().toString();
          try {
              return new URI(uri);
          } catch (URISyntaxException e) {
              // Unlikely edge case: the URI has a forbidden character in the fragment. Strip it & retry.
              try {
                  String stripped = uri.replaceAll("[\\u0000-\\u001F\\u007F-\\u009F\\p{javaWhitespace}]", "");
                  return URI.create(stripped);
              } catch (Exception e1) {
                  throw new RuntimeException(e); // Unexpected!
              }
          }
      }
docs: Returns this URL as a {@link URI java.net.URI}. Because {@code URI} is more strict than this
  class, the returned URI may be semantically different from this URL:
  
  <ul>
  <li>Characters forbidden by URI like {@code [} and {@code |} will be escaped.
  <li>Invalid percent-encoded sequences like {@code %xx} will be encoded like {@code %25xx}.
  <li>Whitespace and control characters in the fragment will be stripped.
  </ul>
  
  <p>These differences may have a significant consequence when the URI is interpretted by a
  webserver. For this reason the {@linkplain URI URI class} and this method should be avoided.