{"record":{"id":"3edff93c3ff8ed87","repo":"grpc/grpc-java","slug":"call-foraddress-instead-3edff9","errorCode":null,"errorMessage":"call forAddress() instead","messagePattern":"call forAddress\\(\\) instead","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"cronet/src/main/java/io/grpc/cronet/CronetChannelBuilder.java","lineNumber":73,"sourceCode":"\n  /** BidirectionalStream.Builder factory used for getting the gRPC BidirectionalStream. */\n  public static abstract class StreamBuilderFactory {\n    public abstract BidirectionalStream.Builder newBidirectionalStreamBuilder(\n        String url, BidirectionalStream.Callback callback, Executor executor);\n  }\n\n  /** Creates a new builder for the given server host, port and CronetEngine. */\n  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;","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/cronet/src/main/java/io/grpc/cronet/CronetChannelBuilder.java#L55-L91","documentation":"CronetChannelBuilder.forTarget(String) is deliberately unsupported: Cronet channels require a CronetEngine, which the target-string overload cannot supply. The method is annotated @DoNotCall and always throws UnsupportedOperationException to force callers onto forAddress(String, int, CronetEngine).","triggerScenarios":"Calling CronetChannelBuilder.forTarget(\"some-target\") or code paths that build a channel via a generic ManagedChannelBuilder.forTarget-style call that resolves to this overload.","commonSituations":"Shared channel-factory code that builds channels by target string for all transports; migration from OkHttp/Netty builders to Cronet without updating the builder entry point.","solutions":["Replace forTarget(target) with CronetChannelBuilder.forAddress(host, port, cronetEngine)","Construct or obtain a CronetEngine (CronetEngine.Builder(context).build()) and pass it to forAddress","Abstract the transport behind a factory so Cronet-specific creation (engine required) is explicit"],"exampleFix":"// before\nManagedChannel ch = CronetChannelBuilder.forTarget(\"dns:///api.example.com:443\").build();\n// after\nCronetEngine engine = new CronetEngine.Builder(context).build();\nManagedChannel ch = CronetChannelBuilder.forAddress(\"api.example.com\", 443, engine).build();","handlingStrategy":"fallback","validationCode":"// Route Cronet channel creation through a factory that requires an engine\nManagedChannel createChannel(String host, int port, CronetEngine engine) {\n  java.util.Objects.requireNonNull(engine, \"CronetEngine required for CronetChannelBuilder\");\n  return CronetChannelBuilder.forAddress(host, port, engine).build();\n}","typeGuard":null,"tryCatchPattern":"try {\n  channel = CronetChannelBuilder.forTarget(target); // unsupported\n} catch (UnsupportedOperationException e) {\n  // migrate: build with forAddress(host, port, cronetEngine)\n  channel = CronetChannelBuilder.forAddress(host, port, engine).build();\n}","preventionTips":["Never call forTarget on CronetChannelBuilder — it is @DoNotCall by design","Always construct a CronetEngine before channel creation","Centralize channel building in one factory so transport quirks are handled once"],"tags":["grpc","android","cronet","unsupported-operation","channel-builder"],"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"}