apache/dubbo · error · IllegalStateException
Cannot assign nested class when refreshing config: <classNam
Error message
Cannot assign nested class when refreshing config: <className>
What it means
Thrown by AbstractConfig.assignProperties on the nested-setter branch: while refreshing, Dubbo instantiates a nested config class (via clazz.getDeclaredConstructor().newInstance()), populates it, and calls the setter. A ReflectiveOperationException — typically a missing accessible no-arg constructor or inaccessible class — is wrapped here.
Source
Thrown at dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java:932
// if mode is others, override with new map
if (overrideIfAbsent) {
newMap.putAll(oldMap);
} else if (overrideAll) {
oldMap.forEach(newMap::putIfAbsent);
}
invokeSetParameters(newMap, obj);
} else if (isNestedSetter(obj, method)) {
try {
Class<?> clazz = method.getParameterTypes()[0];
Object inner = clazz.getDeclaredConstructor().newInstance();
String fieldName = MethodUtils.extractFieldName(method);
Map<String, String> subProperties = ConfigurationUtils.getSubProperties(properties, fieldName);
InmemoryConfiguration subPropsConfiguration = new InmemoryConfiguration(subProperties);
assignProperties(inner, environment, subProperties, subPropsConfiguration, configMode);
method.invoke(obj, inner);
} catch (ReflectiveOperationException e) {
throw new IllegalStateException(
"Cannot assign nested class when refreshing config: "
+ obj.getClass().getName(),
e);
}
}
}
}
private boolean isPropertySet(List<Method> methods, String propertyName) {
try {
String getterName = calculatePropertyToGetter(propertyName);
Method getterMethod = findGetMethod(methods, getterName);
if (getterMethod == null) {
return false;
}
Object oldOne = getterMethod.invoke(this);
if (oldOne != null) {
return true;View on GitHub (pinned to 3a3043227f)
Solutions
- Ensure the nested config class has a public no-arg constructor.
- Make the nested config class public and accessible to Dubbo's classloader.
- Use a concrete class, not an interface or abstract class, as the nested config type.
- Verify the classpath contains the expected Dubbo version and the nested class signature.
Example fix
// before
public class MyNestedConfig {
public MyNestedConfig(String arg) {} // no no-arg ctor
}
// after
public class MyNestedConfig {
public MyNestedConfig() {}
public MyNestedConfig(String arg) {}
} Defensive patterns
Strategy: validation
Validate before calling
void assertInstantiableNested(Class<?> clazz) throws NoSuchMethodException {
int mods = clazz.getModifiers();
if (java.lang.reflect.Modifier.isAbstract(mods) || java.lang.reflect.Modifier.isInterface(mods))
throw new IllegalStateException(clazz + " must be concrete");
clazz.getDeclaredConstructor(); // requires public/accessible no-arg ctor
} Type guard
boolean isConcreteWithNoArgCtor(Class<?> c) {
int m = c.getModifiers();
if (java.lang.reflect.Modifier.isAbstract(m) || java.lang.reflect.Modifier.isInterface(m)) return false;
try { c.getDeclaredConstructor(); return true; } catch (NoSuchMethodException e) { return false; }
} Try / catch
try {
config.refresh();
} catch (IllegalStateException e) {
if (e.getMessage().startsWith("Cannot assign nested class when refreshing config")) {
// add a public no-arg ctor to the named nested class
}
throw e;
} Prevention
- Give every nested config class a public no-arg constructor.
- Use concrete classes (not interfaces/abstract) for nested config types.
- Keep nested config classes public and on the classpath.
When it happens
Trigger: A nested config property (e.g. <dubbo:service><dubbo:provider .../></dubbo:service> or a nested config setter) targets a class that lacks a public no-arg constructor, is an interface/abstract class, or is inaccessible. Dubbo cannot create the nested instance during refresh.
Common situations: A custom nested config class with only a parameterized constructor. A nested config class that is non-public or in a closed module. An interface used as a nested config type instead of a concrete class. Classpath/version mismatch where the nested class changed shape.
Related errors
- Failed to override field value of config bean: <this>
- Append parameters failed: <message>
- Can not merge result because missing method [ {merger} ] in
- More than 1 default extension name on extension {}: {}
- cannot find field %s,field is null
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/1abb8f359be32998.
Report an issue: GitHub.