quarkusio/quarkus · error · IllegalStateException

Different default scopes defined for additional bean class:

Error message

Different default scopes defined for additional bean class: <beanClass>
	 - scopes: <defaultScope> and <existingDefaultScope>

What it means

Two or more AdditionalBeanBuildItem contributions assign different default scopes to the same bean class. The ArcProcessor builds a map of bean class -> default scope during initialize() and detects the conflict as an IllegalStateException.

Source

Thrown at extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcProcessor.java:193

            Optional<TestClassPredicateBuildItem> testClassPredicate,
            Capabilities capabilities,
            CustomScopeAnnotationsBuildItem customScopes,
            LaunchModeBuildItem launchModeBuildItem,
            BuildProducer<CompletedApplicationClassPredicateBuildItem> applicationClassPredicateProducer) {

        if (!arcConfig.isRemoveUnusedBeansFieldValid()) {
            throw new IllegalArgumentException("Invalid configuration value set for 'quarkus.arc.remove-unused-beans'." +
                    " Please use one of " + ArcConfig.ALLOWED_REMOVE_UNUSED_BEANS_VALUES);
        }

        // bean type -> default scope (may be null)
        Map<String, DotName> additionalBeanTypes = new HashMap<>();
        for (AdditionalBeanBuildItem additionalBean : additionalBeans) {
            DotName defaultScope = additionalBean.getDefaultScope();
            for (String beanClass : additionalBean.getBeanClasses()) {
                DotName existingDefaultScope = additionalBeanTypes.get(beanClass);
                if (existingDefaultScope != null && defaultScope != null && !existingDefaultScope.equals(defaultScope)) {
                    throw new IllegalStateException("Different default scopes defined for additional bean class: " + beanClass
                            + "\n\t - scopes: " + defaultScope + " and "
                            + existingDefaultScope);
                }
                additionalBeanTypes.put(beanClass, defaultScope);
            }
        }

        Set<DotName> generatedClassNames = beanArchiveIndex.getGeneratedClassNames();
        IndexView index = beanArchiveIndex.getIndex();
        BeanProcessor.Builder builder = BeanProcessor.builder();
        IndexView applicationClassesIndex = applicationIndex.getIndex();
        Predicate<DotName> applicationClassPredicate = new AbstractCompositeApplicationClassesPredicate<DotName>(
                applicationClassesIndex, generatedClassNames, applicationClassPredicates, testClassPredicate) {
            @Override
            protected DotName getDotName(DotName dotName) {
                return dotName;
            }
        };

View on GitHub (pinned to e1c734241f)

Solutions

  1. Remove one of the duplicate AdditionalBeanBuildItem registrations for the class
  2. Align the default scopes so both registrations agree
  3. Annotate the bean class directly with its scope instead of using additional beans

Example fix

// before
AdditionalBeanBuildItem.builder().addBeanClasses("com.acme.Foo").setDefaultScope(ApplicationScoped.class).build();
AdditionalBeanBuildItem.builder().addBeanClasses("com.acme.Foo").setDefaultScope(Singleton.class).build();
// after
AdditionalBeanBuildItem.builder().addBeanClasses("com.acme.Foo").setDefaultScope(ApplicationScoped.class).build();
Defensive patterns

Strategy: validation

Validate before calling

Map<String,String> seen = new HashMap<>();
for (AdditionalBeanBuildItem b : items)
    for (String cls : b.getBeanClasses()) {
        String prev = seen.put(cls, String.valueOf(b.getDefaultScope()));
        if (prev != null && !prev.equals(String.valueOf(b.getDefaultScope()))) throw new IllegalStateException("Scope conflict for " + cls);
    }

Prevention

When it happens

Trigger: Registering the same class via two AdditionalBeanBuildItem calls with different @DefaultScope/defaultScope values, e.g. one extension adds Foo with @ApplicationScoped default and another adds Foo with @Singleton default.

Common situations: Two extensions both registering a shared library bean with different scopes; an application adding an additional bean that a dependency extension already registers with a different default scope; refactors that duplicate registrations.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/b0b80161bc5a2ef9. Report an issue: GitHub.