{"record":{"id":"4814fe43ec66c27d","repo":"grpc/grpc-java","slug":"failed-to-create-okhttpchannelbuilder","errorCode":null,"errorMessage":"Failed to create OkHttpChannelBuilder","messagePattern":"Failed to create OkHttpChannelBuilder","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"android/src/main/java/io/grpc/android/UdsChannelBuilder.java","lineNumber":87,"sourceCode":"      throw new UnsupportedOperationException(\"OkHttpChannelBuilder not found on the classpath\");\n    }\n    try {\n      // Target 'dns:///127.0.0.1' is unused, but necessary as an argument for OkHttpChannelBuilder.\n      // An IP address is used instead of localhost to avoid a DNS lookup (see #11442). This should\n      // work even if IPv4 is unavailable, as the DNS resolver doesn't need working IPv4 to parse an\n      // IPv4 address. Unavailable IPv4 fails when we connect(), not at resolution time.\n      // TLS is unsupported because Conscrypt assumes the platform Socket implementation to improve\n      // performance by using the file descriptor directly.\n      Object o = OKHTTP_CHANNEL_BUILDER_CLASS\n          .getMethod(\"forTarget\", String.class, ChannelCredentials.class)\n          .invoke(null, \"dns:///127.0.0.1\", InsecureChannelCredentials.create());\n      ManagedChannelBuilder<?> builder = OKHTTP_CHANNEL_BUILDER_CLASS.cast(o);\n      OKHTTP_CHANNEL_BUILDER_CLASS\n          .getMethod(\"socketFactory\", SocketFactory.class)\n          .invoke(builder, new UdsSocketFactory(path, namespace));\n      return builder.proxyDetector(GrpcUtil.NOOP_PROXY_DETECTOR);\n    } catch (IllegalAccessException e) {\n      throw new RuntimeException(\"Failed to create OkHttpChannelBuilder\", e);\n    } catch (NoSuchMethodException e) {\n      throw new RuntimeException(\"Failed to create OkHttpChannelBuilder\", e);\n    } catch (InvocationTargetException e) {\n      throw new RuntimeException(\"Failed to create OkHttpChannelBuilder\", e);\n    }\n  }\n\n  private UdsChannelBuilder() {}\n}\n","sourceCodeStart":69,"sourceCodeEnd":97,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/android/src/main/java/io/grpc/android/UdsChannelBuilder.java#L69-L97","documentation":"forPath() reflects on the OkHttpChannelBuilder to call socketFactory(SocketFactory) on it. An IllegalAccessException means the reflection call was blocked by Java access rules — the OkHttpChannelBuilder class is visible by name but the JVM denied invoking the method, typically due to restrictive class loading or modular access controls. The method wraps it in a RuntimeException with this message.","triggerScenarios":"Calling UdsChannelBuilder.forPath() when OkHttpChannelBuilder is on the classpath but the reflective OKHTTP_CHANNEL_BUILDER_CLASS.getMethod(\"socketFactory\", SocketFactory.class).invoke(...) is denied by access control (IllegalAccessException).","commonSituations":"Multi-classloader environments (custom Android classloaders, dynamic feature modules) where the class was loaded in a restrictive loader; exotic runtime classloader setups rarely seen in standard Android apps.","solutions":["Unwrap the cause in the RuntimeException to confirm which reflection step failed and verify OkHttpChannelBuilder is loaded by the app classloader.","Ensure grpc-okhttp is a normal compile/runtime dependency of the main app module, not a separate plugin classloader.","Remove ProGuard rules that make OkHttpChannelBuilder members inaccessible.","As a diagnostic, call Class.forName(\"io.grpc.okhttp.OkHttpChannelBuilder\") yourself and log its ClassLoader."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"Class<?> c = Class.forName(\"io.grpc.okhttp.OkHttpChannelBuilder\");\nif (c.getMethod(\"socketFactory\", SocketFactory.class) == null) { /* unreachable, but surfaces access errors early */ }","typeGuard":null,"tryCatchPattern":"try {\n  channel = UdsChannelBuilder.forPath(path, ns).build();\n} catch (RuntimeException e) {\n  Throwable cause = e.getCause();\n  if (cause instanceof IllegalAccessException) { /* classloader/access issue: log loader of OkHttpChannelBuilder */ }\n  throw e;\n}","preventionTips":["Keep grpc-okhttp in the main app module so the app classloader loads it.","Avoid loading gRPC classes in isolated plugin/dynamic-feature classloaders.","Audit ProGuard rules for access restrictions on io.grpc.okhttp."],"tags":["grpc","android","reflection","illegal-access"],"backgroundTag":"missing-dependency","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"}