{"record":{"id":"d3cfbfe96b8a9e39","repo":"grpc/grpc-java","slug":"no-authority-path-cannot-start-with","errorCode":null,"errorMessage":"No authority -- Path cannot start with '//'","messagePattern":"No authority -- Path cannot start with '//'","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/io/grpc/Uri.java","lineNumber":189,"sourceCode":"  @Nullable private final String fragment;\n\n  private Uri(Builder builder) {\n    this.scheme = checkNotNull(builder.scheme, \"scheme\");\n    this.userInfo = builder.userInfo;\n    this.host = builder.host;\n    this.port = builder.port;\n    this.path = builder.path;\n    this.query = builder.query;\n    this.fragment = builder.fragment;\n\n    // Checks common to the parse() and Builder code paths.\n    if (hasAuthority()) {\n      if (!path.isEmpty() && !path.startsWith(\"/\")) {\n        throw new IllegalArgumentException(\"Has authority -- Non-empty path must start with '/'\");\n      }\n    } else {\n      if (path.startsWith(\"//\")) {\n        throw new IllegalArgumentException(\"No authority -- Path cannot start with '//'\");\n      }\n    }\n  }\n\n  /**\n   * Parses a URI from its string form.\n   *\n   * @throws URISyntaxException if 's' is not a valid RFC 3986 URI.\n   */\n  public static Uri parse(String s) throws URISyntaxException {\n    try {\n      return create(s);\n    } catch (IllegalArgumentException e) {\n      throw new URISyntaxException(s, e.getMessage());\n    }\n  }\n\n  /**","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/api/src/main/java/io/grpc/Uri.java#L171-L207","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set the authority explicitly (setAuthority) instead of embedding '//host' in the path","Strip the leading '//' from the path, or add a scheme so the '//' is parsed as an authority","Use Uri.parse() on a complete, well-formed URI string rather than constructing parts by hand"],"exampleFix":"// before\nUri.parse(\"grpc//host:443/x\") // '//host:443' parsed as path, no authority -> throws\n// after\nUri.parse(\"grpc://host:443/x\"); // proper scheme + authority","handlingStrategy":"validation","validationCode":"if (!hasAuthority && path.startsWith(\"//\")) throw new IllegalArgumentException(\"path '//' requires authority\");","typeGuard":null,"tryCatchPattern":"try {\n  uri = Uri.parse(s);\n} catch (IllegalArgumentException | URISyntaxException e) {\n  throw new IllegalArgumentException(\"Malformed URI '\" + s + \"': \" + e.getMessage(), e);\n}","preventionTips":["Never embed '//host' in the path; use setAuthority","Require a scheme for protocol-relative inputs before parsing","Prefer parse() over manual construction"],"tags":["uri","rfc3986","validation"],"backgroundTag":"invalid-url-format","analyzedSha":"64daddc1f3d1975670f769f3e97bde8b2ba32d25","analyzedAt":"2026-09-08T06:14:57.704Z","contentChangedAt":"2026-09-08T06:14:57.704Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}