grpc/grpc-java · error · IllegalArgumentException

No authority -- Path cannot start with '//'

Error message

No authority -- Path cannot start with '//'

What it means

Uri's constructor rejects a path starting with '//' when the URI has no authority component. Per RFC 3986, '//' at the start of the path implies an authority, so a scheme-less authority-less URI with such a path is malformed. An IllegalArgumentException is thrown.

Source

Thrown at api/src/main/java/io/grpc/Uri.java:189

  @Nullable private final String fragment;

  private Uri(Builder builder) {
    this.scheme = checkNotNull(builder.scheme, "scheme");
    this.userInfo = builder.userInfo;
    this.host = builder.host;
    this.port = builder.port;
    this.path = builder.path;
    this.query = builder.query;
    this.fragment = builder.fragment;

    // Checks common to the parse() and Builder code paths.
    if (hasAuthority()) {
      if (!path.isEmpty() && !path.startsWith("/")) {
        throw new IllegalArgumentException("Has authority -- Non-empty path must start with '/'");
      }
    } else {
      if (path.startsWith("//")) {
        throw new IllegalArgumentException("No authority -- Path cannot start with '//'");
      }
    }
  }

  /**
   * Parses a URI from its string form.
   *
   * @throws URISyntaxException if 's' is not a valid RFC 3986 URI.
   */
  public static Uri parse(String s) throws URISyntaxException {
    try {
      return create(s);
    } catch (IllegalArgumentException e) {
      throw new URISyntaxException(s, e.getMessage());
    }
  }

  /**

View on GitHub (pinned to 64daddc1f3)

Solutions

  1. Set the authority explicitly (setAuthority) instead of embedding '//host' in the path
  2. Strip the leading '//' from the path, or add a scheme so the '//' is parsed as an authority
  3. Use Uri.parse() on a complete, well-formed URI string rather than constructing parts by hand

Example fix

// before
Uri.parse("grpc//host:443/x") // '//host:443' parsed as path, no authority -> throws
// after
Uri.parse("grpc://host:443/x"); // proper scheme + authority
Defensive patterns

Strategy: validation

Validate before calling

if (!hasAuthority && path.startsWith("//")) throw new IllegalArgumentException("path '//' requires authority");

Try / catch

try {
  uri = Uri.parse(s);
} catch (IllegalArgumentException | URISyntaxException e) {
  throw new IllegalArgumentException("Malformed URI '" + s + "': " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Building or parsing a Uri without an authority whose path begins with '//', e.g. "scheme://host" mis-parsed so that '//host' ended up in the path, or builder code doing setPath("//host/x") without setAuthority.

Common situations: Manual string handling that strips the scheme but leaves '//host' in the path; protocol-relative URLs ('//example.com/x') fed into a parser that requires a scheme; hand-built URIs for proxies/targets.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of grpc/grpc-java@64daddc1f3 (2026-09-08). Data as JSON: /api/errors/d3cfbfe96b8a9e39. Report an issue: GitHub.