{"record":{"id":"5fdf4f4aa13f896e","repo":"grpc/grpc-java","slug":"cannot-create-a-nameresolver-for-targeturi","errorCode":null,"errorMessage":"cannot create a NameResolver for ${targetUri}","messagePattern":"cannot create a NameResolver for (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/grpc/internal/ManagedChannelImpl.java","lineNumber":691,"sourceCode":"    this.channelz = checkNotNull(builder.channelz);\n    channelz.addRootChannel(this);\n\n    if (!lookUpServiceConfig) {\n      if (defaultServiceConfig != null) {\n        channelLogger.log(\n            ChannelLogLevel.INFO, \"Service config look-up disabled, using default service config\");\n      }\n      serviceConfigUpdated = true;\n    }\n  }\n\n  @VisibleForTesting\n  static NameResolver getNameResolver(\n      UriWrapper targetUri, @Nullable final String overrideAuthority,\n      NameResolverProvider provider, NameResolver.Args nameResolverArgs) {\n    NameResolver resolver = targetUri.newNameResolver(provider, nameResolverArgs);\n    if (resolver == null) {\n      throw new IllegalArgumentException(\"cannot create a NameResolver for \" + targetUri);\n    }\n\n    // We wrap the name resolver in a RetryingNameResolver to give it the ability to retry failures.\n    // TODO: After a transition period, all NameResolver implementations that need retry should use\n    //       RetryingNameResolver directly and this step can be removed.\n    NameResolver usedNameResolver = RetryingNameResolver.wrap(resolver, nameResolverArgs);\n\n    if (overrideAuthority == null) {\n      return usedNameResolver;\n    }\n\n    return new ForwardingNameResolver(usedNameResolver) {\n      @Override\n      public String getServiceAuthority() {\n        return overrideAuthority;\n      }\n    };\n  }","sourceCodeStart":673,"sourceCodeEnd":709,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/core/src/main/java/io/grpc/internal/ManagedChannelImpl.java#L673-L709","documentation":"ManagedChannelImpl.getNameResolver asks the NameResolverProvider to create a resolver for the target URI. When the provider returns null — the target URI's scheme is unknown or the URI is malformed for the installed resolvers — the channel constructor fails fast with this IllegalArgumentException, since a channel cannot operate without name resolution.","triggerScenarios":"ManagedChannelBuilder.forTarget(\"foo://bar\") with an unregistered scheme, a target string like \"localhost:port\" with no dns resolver available on the classpath, or an invalid authority/syntax the URI wrapper cannot parse.","commonSituations":"Missing grpc-services/dns resolution dependency in a shaded or minimal deployment; typos in target strings such as 'unix:/path' without the unix transport on the classpath; passing a bare hostname when a scheme is required by custom providers.","solutions":["Fix the target string to a valid URI, e.g. 'dns:///localhost:50051'.","Ensure the NameResolver provider for the scheme is on the classpath (grpc-core's dns resolver is registered via META-INF/services).","If using a custom scheme, register its NameResolverProvider with NameResolverRegistry.getDefaultRegistry().","Validate the target with target.toString()/URI parsing before building the channel."],"exampleFix":"// before\nManagedChannel ch = ManagedChannelBuilder.forTarget(\"my-scheme://svc\").build();\n// after\nManagedChannel ch = ManagedChannelBuilder.forTarget(\"dns:///svc.example.com:50051\").build();","handlingStrategy":"validation","validationCode":"static boolean resolvableTarget(String target) {\n  java.net.URI uri = java.net.URI.create(target);\n  String scheme = uri.getScheme() == null ? \"dns\" : uri.getScheme();\n  return !io.grpc.NameResolverRegistry.getDefaultRegistry()\n      .providers().stream().noneMatch(p -> scheme.equals(p.getDefaultScheme()));\n}\n// call before forTarget(); also verify URI parses","typeGuard":null,"tryCatchPattern":"try {\n  return ManagedChannelBuilder.forTarget(target).build();\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"cannot create a NameResolver\")) {\n    return ManagedChannelBuilder.forTarget(\"dns:///\" + target).build();\n  }\n  throw e;\n}","preventionTips":["Prefer explicit 'dns:///host:port' target URIs.","Keep grpc-core's dns NameResolver on the classpath.","Register custom NameResolverProviders before channel construction."],"tags":["grpc","name-resolution","uri","classpath"],"backgroundTag":"invalid-url","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"}