SonarSource/sonarqube · error · IllegalStateException
No parent container
Error message
No parent container
What it means
getParentComponentByType() throws this IllegalStateException when the container has no parent (parent == null). The method is only meaningful in hierarchical (e.g. web/app) container setups where a child container delegates lookups to its parent; a root container cannot fulfill a parent lookup, so it fails fast instead of returning null.
Source
Thrown at sonar-core/src/main/java/org/sonar/core/platform/SpringComponentContainer.java:131
}
}
return this;
}
@Override
public void addWebApiV2ConfigurationClass(Class<?> clazz) {
webConfigurationClasses.add(clazz);
}
@Override
public Set<Class<?>> getWebApiV2ConfigurationClasses() {
return Set.copyOf(webConfigurationClasses);
}
@Override
public <T> T getParentComponentByType(Class<T> type) {
if (parent == null) {
throw new IllegalStateException("No parent container");
} else {
return parent.getComponentByType(type);
}
}
@Override
public <T> List<T> getParentComponentsByType(Class<T> type) {
if (parent == null) {
throw new IllegalStateException("No parent container");
} else {
return parent.getComponentsByType(type);
}
}
private <T> void registerInstance(T instance) {
Supplier<T> supplier = () -> instance;
Class<T> clazz = (Class<T>) instance.getClass();
context.registerBean(componentKeys.ofInstance(instance), clazz, supplier);View on GitHub (pinned to 184c821202)
Solutions
- Move the component that performs the lookup into a child container that actually has a parent.
- Guard the call: check for parent availability or use getComponentByType on the local container when at root level.
- Restructure component wiring so root-level components do not depend on parent-level components.
Example fix
// before ParentService s = container.getParentComponentByType(ParentService.class); // after ParentService s = container.hasParent() ? container.getParentComponentByType(ParentService.class) : container.getComponentByType(ParentService.class);
Defensive patterns
Strategy: type-guard
Validate before calling
if (container.isRoot()) {
throw new IllegalStateException("Cannot do parent lookup at root container");
} Type guard
ParentService lookupOrNull(SpringComponentContainer c, Class<ParentService> t) {
return c.isRoot() ? null : c.getParentComponentByType(t);
} Try / catch
try {
return container.getParentComponentByType(type);
} catch (IllegalStateException e) {
return container.getComponentByType(type); // root-level fallback
} Prevention
- Only perform parent lookups from components registered in child containers.
- Design shared startup code to branch on container level.
- Document which components require a hierarchical container.
When it happens
Trigger: Calling container.getParentComponentByType(SomeType.class) on a root container created without a parent argument (e.g. new SpringComponentContainer(config) with no parent).
Common situations: Code shared between web-server child containers and standalone/root contexts calling parent lookups unconditionally; initializing a component at the wrong container level so it runs in a container without a parent.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/2e0f3df300158177.
Report an issue: GitHub.