{"record":{"id":"7a98dbd9478f6fcb","repo":"grpc/grpc-java","slug":"caller-failed-to-initialize-xds-client-supplier","errorCode":null,"errorMessage":"Caller failed to initialize XDS_CLIENT_SUPPLIER","messagePattern":"Caller failed to initialize XDS_CLIENT_SUPPLIER","errorType":"exception","errorClass":"XdsInitializationException","httpStatus":null,"severity":"error","filePath":"xds/src/main/java/io/grpc/xds/XdsNameResolver.java","lineNumber":1121,"sourceCode":"\n    @Override\n    public XdsClient returnObject(XdsClient xdsClient) {\n      return xdsClientPool.returnObject(xdsClient);\n    }\n  }\n\n  private static final class SupplierXdsClientPool implements XdsClientPool {\n    private final Supplier<XdsClient> xdsClientSupplier;\n\n    SupplierXdsClientPool(Supplier<XdsClient> xdsClientSupplier) {\n      this.xdsClientSupplier = checkNotNull(xdsClientSupplier, \"xdsClientSupplier\");\n    }\n\n    @Override\n    public XdsClient getObject() throws XdsInitializationException {\n      XdsClient xdsClient = xdsClientSupplier.get();\n      if (xdsClient == null) {\n        throw new XdsInitializationException(\"Caller failed to initialize XDS_CLIENT_SUPPLIER\");\n      }\n      return xdsClient;\n    }\n\n    @Override\n    public XdsClient returnObject(XdsClient xdsClient) {\n      return null;\n    }\n  }\n\n  static final class RawMessageClientInterceptor implements ClientInterceptor {\n    private static final MethodDescriptor.Marshaller<InputStream> RAW_MARSHALLER =\n        new MethodDescriptor.Marshaller<InputStream>() {\n          @Override\n          public InputStream stream(InputStream value) {\n            return value;\n          }\n","sourceCodeStart":1103,"sourceCodeEnd":1139,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/xds/src/main/java/io/grpc/xds/XdsNameResolver.java#L1103-L1139","documentation":"XdsNameResolver's XdsClient supplier was never initialized: the holder's get() returned null, meaning the caller was expected to set XDS_CLIENT_SUPPLIER (typically via an injected supplier in tests or embedded usage) but did not. This is an internal initialization guard surfaced as XdsInitializationException.","triggerScenarios":"Constructing/starting XdsNameResolver (or the XdsResolver it delegates to) where the static/injected XDS_CLIENT_SUPPLIER was never set, so getObject() in the pool returns null at XdsNameResolver.java:1121.","commonSituations":"Unit tests instantiating the resolver without registering a supplier; embedding gRPC xDS internals directly instead of going through nameResolverProvider; classloader/shading issues leaving the static field unset.","solutions":["Use the standard XdsNameResolverProvider / xDS bootstrapping path instead of constructing XdsNameResolver directly","In tests, set the XDS_CLIENT_SUPPLIER (or inject an XdsClient supplier) before resolving","Check that no double-shading of io.grpc.xds leaves two copies of the class with separate statics"],"exampleFix":"// before\nXdsNameResolver resolver = new XdsNameResolver(authority, target, ...); // supplier never set\n// after\nNameResolverResolverProvider provider = new XdsNameResolverProvider();\nNameResolver resolver = provider.newNameResolver(targetUri, args);","handlingStrategy":"type-guard","validationCode":"// Ensure a supplier is registered before resolving\nSupplier<XdsClient> supplier = getXdsClientSupplierOrNull();\nif (supplier == null || supplier.get() == null) {\n  throw new IllegalStateException(\"XDS_CLIENT_SUPPLIER not initialized\");\n}","typeGuard":"static boolean isSupplierReady(Supplier<XdsClient> s) {\n  return s != null && s.get() != null;\n}","tryCatchPattern":"try {\n  NameResolver nr = provider.newNameResolver(uri, args);\n  nr.start(watcher);\n} catch (XdsInitializationException e) {\n  log.error(\"xDS not initialized: {}\", e.getMessage());\n}","preventionTips":["Resolve addresses through the standard xDS name resolver provider, not internal classes","In tests, always install a fake XdsClient supplier before creating resolvers","Avoid double-shading io.grpc.xds in fat jars"],"tags":["xds","grpc","initialization","internal"],"backgroundTag":"internal-invariant-violation","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"}