{"record":{"id":"774c0cb69e479aa7","repo":"grpc/grpc-java","slug":"call-foraddress-string-int-cronetengine-instead","errorCode":null,"errorMessage":"call forAddress(String, int, CronetEngine) instead","messagePattern":"call forAddress\\(String, int, CronetEngine\\) instead","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"cronet/src/main/java/io/grpc/cronet/CronetChannelBuilder.java","lineNumber":81,"sourceCode":"  public static CronetChannelBuilder forAddress(String host, int port, CronetEngine cronetEngine) {\n    Preconditions.checkNotNull(cronetEngine, \"cronetEngine\");\n    return new CronetChannelBuilder(host, port, cronetEngine);\n  }\n\n  /**\n   * Always fails.  Call {@link #forAddress(String, int, CronetEngine)} instead.\n   */\n  @DoNotCall(\"Unsupported. Use forAddress(String, int, CronetEngine) instead\")\n  public static CronetChannelBuilder forTarget(String target) {\n    throw new UnsupportedOperationException(\"call forAddress() instead\");\n  }\n\n  /**\n   * Always fails.  Call {@link #forAddress(String, int, CronetEngine)} instead.\n   */\n  @DoNotCall(\"Unsupported. Use forAddress(String, int, CronetEngine) instead\")\n  public static CronetChannelBuilder forAddress(String name, int port) {\n    throw new UnsupportedOperationException(\"call forAddress(String, int, CronetEngine) instead\");\n  }\n\n  @Nullable\n  private ScheduledExecutorService scheduledExecutorService;\n\n  private final CronetEngine cronetEngine;\n  private final ManagedChannelImplBuilder managedChannelImplBuilder;\n  private final TransportTracer.Factory transportTracerFactory = TransportTracer.getDefaultFactory();\n\n  private boolean alwaysUsePut = false;\n\n  private int maxMessageSize = DEFAULT_MAX_MESSAGE_SIZE;\n\n  /**\n   * If true, indicates that the transport may use the GET method for RPCs, and may include the\n   * request body in the query params.\n   */\n  private final boolean useGetForSafeMethods = false;","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/cronet/src/main/java/io/grpc/cronet/CronetChannelBuilder.java#L63-L99","documentation":"CronetChannelBuilder.forAddress(String, int) is intentionally unimplemented. Cronet transport requires a CronetEngine to build streams, so the two-argument forAddress overload inherited from the generic builder API always throws UnsupportedOperationException. The annotated @DoNotCall marker signals compile-time discouragement as well.","triggerScenarios":"Calling CronetChannelBuilder.forAddress(host, port) directly instead of the three-argument overload forAddress(String name, int port, CronetEngine cronetEngine).","commonSituations":"Migrating generic gRPC channel-building code (written for netty or okHttp) to Cronet without adapting to the CronetEngine requirement; copying builder setup from docs for other transports.","solutions":["Use CronetChannelBuilder.forAddress(name, port, cronetEngine), passing a constructed CronetEngine (e.g. new CronetEngine.Builder(context).build()).","If you have a target URI, use forTarget(String) with the engine-configured builder instead.","Replace the Cronet transport with another transport (e.g. OkHttpChannelBuilder) if an engine cannot be supplied."],"exampleFix":"// before\nManagedChannel ch = CronetChannelBuilder.forAddress(\"example.com\", 443).build();\n// after\nCronetEngine engine = new CronetEngine.Builder(context).build();\nManagedChannel ch = CronetChannelBuilder.forAddress(\"example.com\", 443, engine).build();","handlingStrategy":"validation","validationCode":"if (engine == null) throw new IllegalArgumentException(\"CronetEngine required: use forAddress(name, port, engine)\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use the three-argument forAddress overload with a CronetEngine","Heed @DoNotCall annotations and IDE warnings","Centralize channel creation in one factory method"],"tags":["grpc","cronet","android","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}