{"record":{"id":"9e910a8cf47e7f52","repo":"jax-ml/jax","slug":"argument-to-get-c-api-topology-contained-a-null-po","errorCode":null,"errorMessage":"Argument to get_c_api_topology contained a null pointer.","messagePattern":"Argument to get_c_api_topology contained a null pointer\\.","errorType":"validation","errorClass":"nb::value_error","httpStatus":null,"severity":"error","filePath":"jaxlib/jax.cc","lineNumber":611,"sourceCode":"  // standard registration.\n  m.def(\"get_default_c_api_topology\",\n        [](std::string platform_name, std::string topology_name,\n           const absl::flat_hash_map<std::string, xla::PjRtValueType>& options)\n            -> std::shared_ptr<xla::ifrt::Topology> {\n          return std::make_shared<xla::ifrt::PjRtTopology>(xla::ValueOrThrow(\n              xla::GetCApiTopology(platform_name, topology_name, options)));\n        });\n  m.def(\"get_c_api_topology\",\n        [](nb::capsule c_api, std::string topology_name,\n           const absl::flat_hash_map<std::string, xla::PjRtValueType>& options)\n            -> std::shared_ptr<xla::ifrt::Topology> {\n          if (c_api.name() == nullptr ||\n              std::string_view(c_api.name()) != \"pjrt_c_api\") {\n            throw nb::value_error(\n                \"Argument to get_c_api_topology was not a pjrt_c_api capsule.\");\n          }\n          if (c_api.data() == nullptr) {\n            throw nb::value_error(\n                \"Argument to get_c_api_topology contained a null pointer.\");\n          }\n          return std::make_shared<xla::ifrt::PjRtTopology>(xla::ValueOrThrow(\n              xla::GetCApiTopology(static_cast<const PJRT_Api*>(c_api.data()),\n                                   topology_name, options)));\n        });\n  m.def(\"get_topology_for_devices\",\n        [](const std::vector<nb_class_ptr<PyDevice>>& py_devices) {\n          if (py_devices.empty()) {\n            throw nb::value_error(\n                \"get_topology_for_devices requires >= 1 devices.\");\n          }\n          auto client = py_devices[0]->client();\n          absl::InlinedVector<xla::ifrt::Device*, 1> ifrt_devices;\n          ifrt_devices.reserve(py_devices.size());\n          for (const auto& py_device : py_devices) {\n            if (py_device->client().get() != client.get()) {\n              throw nb::value_error(","sourceCodeStart":593,"sourceCodeEnd":629,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jaxlib/jax.cc#L593-L629","documentation":"Even a correctly named capsule must carry a non-null pointer; a null payload cannot be dereferenced as PJRT_Api*, so get_c_api_topology rejects it explicitly.","triggerScenarios":"Passing a capsule constructed as nb::capsule(nullptr, 'pjrt_c_api') or a capsule whose pointed-to API was already freed.","commonSituations":"Plugins that return empty capsules on failed initialization; use-after-free of a plugin API handle.","solutions":["Ensure the plugin loaded successfully before distributing its capsule","Re-obtain the capsule from load_pjrt_plugin and check it is non-null"],"exampleFix":"# before\nassert cap is not None\njaxlib.get_c_api_topology(cap, 'topo')\n# after\ncap = jaxlib.load_pjrt_plugin(p, library_path)\nassert cap is not None and ctypes.cast(cap, ctypes.c_void_p).value\njaxlib.get_c_api_topology(cap, 'topo')","handlingStrategy":"validation","validationCode":"import ctypes\nassert ctypes.cast(c_api, ctypes.c_void_p).value is not None","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify plugin load succeeded before using its capsule","Never reuse capsules after unloading a plugin"],"tags":["jax","pjrt","topology","capsule","null-pointer"],"backgroundTag":"invalid-capsule-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}