{"record":{"id":"de657abe63aed8cc","repo":"grpc/grpc-java","slug":"use-forport-int-servercredentials-instead","errorCode":null,"errorMessage":"Use forPort(int, ServerCredentials) instead","messagePattern":"Use forPort\\(int, ServerCredentials\\) instead","errorType":"validation","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"okhttp/src/main/java/io/grpc/okhttp/OkHttpServerBuilder.java","lineNumber":95,"sourceCode":"  private static final long MIN_MAX_CONNECTION_IDLE_NANO = TimeUnit.SECONDS.toNanos(1L);\n  static final long MAX_CONNECTION_AGE_NANOS_DISABLED = Long.MAX_VALUE;\n  static final long MAX_CONNECTION_AGE_GRACE_NANOS_INFINITE = Long.MAX_VALUE;\n  static final int MAX_CONCURRENT_STREAMS = Integer.MAX_VALUE;\n  private static final long MIN_MAX_CONNECTION_AGE_NANO = TimeUnit.SECONDS.toNanos(1L);\n\n  private static final long AS_LARGE_AS_INFINITE = TimeUnit.DAYS.toNanos(1000L);\n  private static final ObjectPool<Executor> DEFAULT_TRANSPORT_EXECUTOR_POOL =\n      OkHttpChannelBuilder.DEFAULT_TRANSPORT_EXECUTOR_POOL;\n\n  /**\n   * Always throws, to shadow {@code ServerBuilder.forPort()}.\n   *\n   * @deprecated Use {@link #forPort(int, ServerCredentials)} instead\n   */\n  @DoNotCall(\"Always throws. Use forPort(int, ServerCredentials) instead\")\n  @Deprecated\n  public static OkHttpServerBuilder forPort(int port) {\n    throw new UnsupportedOperationException(\"Use forPort(int, ServerCredentials) instead\");\n  }\n\n  /**\n   * Creates a builder for a server listening on {@code port}.\n   */\n  public static OkHttpServerBuilder forPort(int port, ServerCredentials creds) {\n    return forPort(new InetSocketAddress(port), creds);\n  }\n\n  /**\n   * Creates a builder for a server listening on {@code address}.\n   */\n  public static OkHttpServerBuilder forPort(SocketAddress address, ServerCredentials creds) {\n    HandshakerSocketFactoryResult result = handshakerSocketFactoryFrom(creds);\n    if (result.error != null) {\n      throw new IllegalArgumentException(result.error);\n    }\n    return new OkHttpServerBuilder(address, result.factory);","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/okhttp/src/main/java/io/grpc/okhttp/OkHttpServerBuilder.java#L77-L113","documentation":"OkHttpServerBuilder.forPort(int) is a permanently dead static factory: it is annotated @DoNotCall and always throws UnsupportedOperationException. gRPC Java moved port+credentials APIs to take a ServerCredentials argument (for TLS etc.), so the credentials-less overload was removed. Callers must migrate to the two-argument overload.","triggerScenarios":"Any direct call to the deprecated static OkHttpServerBuilder.forPort(int) — e.g. old code written before the API migration — throws immediately.","commonSituations":"Upgrading grpc-java/okhttp to a version where the credentials-less forPort was made fatal; copy-pasted legacy server bootstrap code; tutorials or blog posts written against older gRPC versions.","solutions":["Replace the call with OkHttpServerBuilder.forPort(port, creds), e.g. InsecureServerCredentials.getInsecureInstance() for plaintext","Alternatively use Grpc.newServerBuilderForPort(port, creds) or ServerBuilder.forPort(port, creds) for provider-based construction","If plaintext is all you need, verify the imported class is the correct builder and no stale overload was resolved"],"exampleFix":"// before\nOkHttpServerBuilder builder = OkHttpServerBuilder.forPort(8080);\n// after\nOkHttpServerBuilder builder = OkHttpServerBuilder.forPort(8080, InsecureServerCredentials.getInsecureInstance());","handlingStrategy":"validation","validationCode":"if (useTls) {\n  builder = OkHttpServerBuilder.forPort(port, TlsServerCredentials.newBuilder().keyManager(certChain, privateKey).build());\n} else {\n  builder = OkHttpServerBuilder.forPort(port, InsecureServerCredentials.getInsecureInstance());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call the two-arg forPort(int, ServerCredentials) overload","Use Grpc.newServerBuilderForPort for provider-neutral server creation","Treat @Deprecated @DoNotCall methods as removed during upgrades and fix usages at compile time"],"tags":["grpc","java","deprecated-api","unsupported-operation"],"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"}