{"record":{"id":"6887053d76b92062","repo":"hibernate/hibernate-orm","slug":"bootstrap-registry-should-only-contain-provided-se","errorCode":null,"errorMessage":"Bootstrap registry should only contain provided services","messagePattern":"Bootstrap registry should only contain provided services","errorType":"exception","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/registry/internal/BootstrapServiceRegistryImpl.java","lineNumber":237,"sourceCode":"\t\t}\n\t}\n\n\tprivate synchronized void destroy(ServiceBinding<?> serviceBinding) {\n\t\tserviceBinding.getLifecycleOwner().stopService( serviceBinding );\n\t}\n\n\tpublic boolean isActive() {\n\t\treturn active;\n\t}\n\n\t@Override\n\tpublic @Nullable ServiceRegistry getParentServiceRegistry() {\n\t\treturn null;\n\t}\n\n\t@Override\n\tpublic <R extends Service> R initiateService(ServiceInitiator<R> serviceInitiator) {\n\t\tthrow new ServiceException( \"Bootstrap registry should only contain provided services\" );\n\t}\n\n\t@Override\n\tpublic <R extends Service> void configureService(ServiceBinding<R> binding) {\n\t\tthrow new ServiceException( \"Bootstrap registry should only contain provided services\" );\n\t}\n\n\t@Override\n\tpublic <R extends Service> void injectDependencies(ServiceBinding<R> binding) {\n\t\tthrow new ServiceException( \"Bootstrap registry should only contain provided services\" );\n\t}\n\n\t@Override\n\tpublic <R extends Service> void startService(ServiceBinding<R> binding) {\n\t\tthrow new ServiceException( \"Bootstrap registry should only contain provided services\" );\n\t}\n\n\t@Override","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/registry/internal/BootstrapServiceRegistryImpl.java#L219-L255","documentation":"The BootstrapServiceRegistry only ever hosts services that were explicitly provided to it (ClassLoaderService, IntegratorService, and anything handed to the builder); it has no initiators. Its initiateService() unconditionally throws this ServiceException because initiating services is the job of the StandardServiceRegistry built on top. Hitting it means a service-role lookup was routed to the bootstrap registry for a role it never contained.","triggerScenarios":"Calling getService()/requireService() for a non-provided role on a BootstrapServiceRegistry, or custom registry code that routes service initiation into the bootstrap registry - e.g., bootstrapRegistry.getService(JdbcServices.class) in an integration or test utility.","commonSituations":"Custom integrations or test scaffolding that hold only a BootstrapServiceRegistry and request standard services (JdbcServices, ConnectionProvider, ...); code copied from StandardServiceRegistryBuilder internals; frameworks wiring initiators at the wrong registry level.","solutions":["Build a StandardServiceRegistry on top of the bootstrap registry (StandardServiceRegistryBuilder) and request standard services from it","Only ask the bootstrap registry for the services it was given: ClassLoaderService, IntegratorService, JmxService and explicitly provided services","Review custom ServiceContributor/Integrator code that manipulates registry internals"],"exampleFix":"// before\nBootstrapServiceRegistry boot = new BootstrapServiceRegistryBuilder().build();\nJdbcServices jdbc = boot.getService(JdbcServices.class); // throws\n\n// after\nStandardServiceRegistry registry = new StandardServiceRegistryBuilder(boot).build();\nJdbcServices jdbc = registry.getService(JdbcServices.class);","handlingStrategy":"validation","validationCode":"// Verify the role is bootstrap-provided before lookup\nstatic final Set<Class<?>> BOOTSTRAP_ROLES =\n    Set.of(ClassLoaderService.class, IntegratorService.class, JmxService.class);\nif (!BOOTSTRAP_ROLES.contains(role)) {\n    throw new IllegalArgumentException(\n        role.getSimpleName() + \" is a standard service - query the StandardServiceRegistry\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return registry.getService(role);\n} catch (ServiceException e) {\n    if (e.getMessage().contains(\"Bootstrap registry\")) {\n        // wrong registry level: build/wrap a StandardServiceRegistry and retry there\n    }\n    throw e;\n}","preventionTips":["Request standard services only from a StandardServiceRegistry; bootstrap holds provided services only","In tests, always build StandardServiceRegistryBuilder(bootstrap) before looking up services","Document which services your integration needs and from which registry level"],"tags":["hibernate","service-registry","bootstrap","internal-api","spi"],"backgroundTag":"service-registry-misuse","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}