{"record":{"id":"ae06342226156784","repo":"grpc/grpc-java","slug":"clienttransportfactorybuilder-is-required-use-a-c","errorCode":null,"errorMessage":"ClientTransportFactoryBuilder is required, use a constructor","messagePattern":"ClientTransportFactoryBuilder is required, use a constructor","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/grpc/internal/ManagedChannelImplBuilder.java","lineNumber":84,"sourceCode":"import java.util.concurrent.Executor;\nimport java.util.concurrent.TimeUnit;\nimport java.util.logging.Level;\nimport java.util.logging.Logger;\nimport java.util.regex.Pattern;\nimport javax.annotation.Nullable;\n\n/**\n * Default managed channel builder, for usage in Transport implementations.\n */\npublic final class ManagedChannelImplBuilder\n    extends ManagedChannelBuilder<ManagedChannelImplBuilder> {\n  private static final String DIRECT_ADDRESS_SCHEME = \"directaddress\";\n\n  private static final Logger log = Logger.getLogger(ManagedChannelImplBuilder.class.getName());\n\n  @DoNotCall(\"ClientTransportFactoryBuilder is required, use a constructor\")\n  public static ManagedChannelBuilder<?> forAddress(String name, int port) {\n    throw new UnsupportedOperationException(\n        \"ClientTransportFactoryBuilder is required, use a constructor\");\n  }\n\n  @DoNotCall(\"ClientTransportFactoryBuilder is required, use a constructor\")\n  public static ManagedChannelBuilder<?> forTarget(String target) {\n    throw new UnsupportedOperationException(\n        \"ClientTransportFactoryBuilder is required, use a constructor\");\n  }\n\n  /**\n   * An idle timeout larger than this would disable idle mode.\n   */\n  @VisibleForTesting\n  static final long IDLE_MODE_MAX_TIMEOUT_DAYS = 30;\n\n  /**\n   * The default idle timeout.\n   */","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/core/src/main/java/io/grpc/internal/ManagedChannelImplBuilder.java#L66-L102","documentation":"ManagedChannelImplBuilder extends ManagedChannelBuilder but is internal; unlike public builders it requires a ClientTransportFactory (supplied via a constructor or transport builder) to know how to create connections. The inherited static forAddress() factory method is annotated @DoNotCall and always throws UnsupportedOperationException to steer users to the correct constructors.","triggerScenarios":"Calling ManagedChannelImplBuilder.forAddress(name, port) directly, e.g. via reflection or by mistyping the import so ManagedChannelImplBuilder is used instead of ManagedChannelBuilder.","commonSituations":"Import confusion between io.grpc.ManagedChannelBuilder and io.grpc.internal.ManagedChannelImplBuilder; framework code instantiating the internal builder through its static API.","solutions":["Use io.grpc.ManagedChannelBuilder.forAddress(name, port) (the public API) instead.","If you truly need the internal builder, use its constructor with a ClientTransportFactoryBuilder argument.","Fix the import statement so the public builder class is referenced."],"exampleFix":"// before\nimport io.grpc.internal.ManagedChannelImplBuilder;\nManagedChannelBuilder<?> b = ManagedChannelImplBuilder.forAddress(\"localhost\", 50051);\n// after\nimport io.grpc.ManagedChannelBuilder;\nManagedChannelBuilder<?> b = ManagedChannelBuilder.forAddress(\"localhost\", 50051);","handlingStrategy":"type-guard","validationCode":"Class<?> c = builder.getClass();\nif (c.getName().equals(\"io.grpc.internal.ManagedChannelImplBuilder\")) {\n  throw new IllegalStateException(\"Use io.grpc.ManagedChannelBuilder\");\n}","typeGuard":"boolean isPublicBuilder(ManagedChannelBuilder<?> b) {\n  return !b.getClass().getName().startsWith(\"io.grpc.internal.\");\n}","tryCatchPattern":"try {\n  return builder.forAddress(host, port);\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage().contains(\"ClientTransportFactoryBuilder\")) {\n    return io.grpc.ManagedChannelBuilder.forAddress(host, port);\n  }\n  throw e;\n}","preventionTips":["Import io.grpc.ManagedChannelBuilder, never io.grpc.internal.ManagedChannelImplBuilder, in app code.","Add an import-order/lint rule banning io.grpc.internal imports outside grpc itself.","Search codebase for 'ManagedChannelImplBuilder' usages when upgrading gRPC."],"tags":["grpc","deprecated-api-usage","wrong-class","builder"],"backgroundTag":"deprecated-api-usage","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"}