code: public static URI createURI(String uri) {
          uri = encodeIllegalCharacters(uri);
          URI result = URI.create(uri);
          if (result.getHost() != null && StringUtils.isEmpty(result.getPath())) {
              result =
                      URI.create(createURI(result.getScheme(), result.getHost(), result.getPort(), "/",
                              result.getRawQuery(), result.getRawFragment()));
          }
          return result;
      }
docs: Creates an {@link URI} after escaping some special characters in order to tolerate some incorrect URI types. If
  the uri contains a server name but no path, the path is set to "/" as a browser would do.
  
  @param uri
  the URI as a {@link String}
  @return the URI as a {@link URI} object