apache/dubbo · error · IllegalStateException

Add default config failed: <configType.getSimpleName()>

Error message

Add default config failed: <configType.getSimpleName()>

What it means

Thrown by AbstractConfigManager.checkDefaultAndValidateConfigs() when adding a generated default config (for a required type lacking an explicit one) fails with any exception. The method first tries to create and refresh a default config; if that construction or refresh throws, it wraps the failure with the config type simple name. Validation or required-default logic surfaces here.

Solutions

  1. Provide an explicit config of the required type so the default-creation path is skipped.
  2. Inspect the wrapped cause to find why default construction failed.
  3. Ensure environment/properties needed by the default config are present.

Example fix

// before: relying on auto-default that fails
// (no application config, default creation throws)
// after: explicit config
ApplicationConfig app = new ApplicationConfig();
app.setName("myApp");
configManager.addConfig(app);
Defensive patterns

Strategy: try-catch

Validate before calling

// Provide explicit required config to bypass default-creation path
if (configManager.getConfigs(ApplicationConfig.class).isEmpty()) {
    ApplicationConfig app = new ApplicationConfig();
    app.setName("myApp");
    configManager.addConfig(app);
}
configManager.checkDefaultAndValidateConfigs(ApplicationConfig.class);

Type guard

static boolean hasConfigOfType(ConfigManager cm, Class<? extends AbstractConfig> cls) {
    return !cm.getConfigs(cls).isEmpty();
}

Try / catch

try {
    configManager.checkDefaultAndValidateConfigs(ApplicationConfig.class);
} catch (IllegalStateException e) {
    if (e.getMessage().startsWith("Add default config failed")) {
        ApplicationConfig app = new ApplicationConfig();
        app.setName("myApp");
        configManager.addConfig(app);
    } else throw e;
}

Prevention

When it happens

Trigger: A config type marked for default creation whose default construction/refresh throws (e.g. default ApplicationConfig cannot resolve a required property). Called during the validate phase of bootstrap.

Common situations: Missing a required config and the auto-default path also fails due to environment issues (e.g. default registry address unresolvable). A custom required config type whose default builder is broken.

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/cbb50954ee37c06b. Report an issue: GitHub.

Appendix: source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java:621

     */
    private Set<String> getConfigIdsFromProps(Class<? extends AbstractConfig> clazz) {
        String prefix = CommonConstants.DUBBO + "." + AbstractConfig.getPluralTagName(clazz) + ".";
        return ConfigurationUtils.getSubIds(environment.getConfigurationMaps(), prefix);
    }

    protected <T extends AbstractConfig> void checkDefaultAndValidateConfigs(Class<T> configType) {
        try {
            if (shouldAddDefaultConfig(configType)) {
                T config = createConfig(configType, scopeModel);
                config.refresh();
                if (!isNeedValidation(config) || config.isValid()) {
                    this.addConfig(config);
                } else {
                    logger.info("Ignore invalid config: " + config);
                }
            }
        } catch (Exception e) {
            throw new IllegalStateException("Add default config failed: " + configType.getSimpleName(), e);
        }

        // validate configs
        Collection<T> configs = this.getConfigs(configType);
        if (getConfigValidator() != null) {
            for (T config : configs) {
                getConfigValidator().validate(config);
            }
        }

        // check required default
        if (isRequired(configType) && configs.isEmpty()) {
            throw new IllegalStateException("Default config not found for " + configType.getSimpleName());
        }
    }

    /**
     * The component configuration that does not affect the main process does not need to be verified.

View on GitHub (pinned to 3a3043227f)