spring-projects/spring-framework · error · IllegalArgumentException
Cannot create default implementation for '{interfaceType.get
Error message
Cannot create default implementation for '{interfaceType.getName()}' mixin ({defaultImplType.getName()}): {ex} What it means
DelegatePerTargetObjectIntroductionInterceptor.createNewDelegate throws IllegalArgumentException when the defaultImplType cannot be instantiated via ReflectionUtils.accessibleConstructor(defaultImplType).newInstance(). This per-target mixin creates a fresh delegate object per advised target; if defaultImplType has no accessible no-arg constructor (or is abstract/interface) the eager delegate creation in the constructor fails.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.java:139
private Object getIntroductionDelegateFor(@Nullable Object targetObject) {
synchronized (this.delegateMap) {
if (this.delegateMap.containsKey(targetObject)) {
return this.delegateMap.get(targetObject);
}
else {
Object delegate = createNewDelegate();
this.delegateMap.put(targetObject, delegate);
return delegate;
}
}
}
private Object createNewDelegate() {
try {
return ReflectionUtils.accessibleConstructor(this.defaultImplType).newInstance();
}
catch (Throwable ex) {
throw new IllegalArgumentException("Cannot create default implementation for '" +
this.interfaceType.getName() + "' mixin (" + this.defaultImplType.getName() + "): " + ex);
}
}
}
View on GitHub (pinned to e8729d0438)
Solutions
- Ensure defaultImplType is a concrete class with an accessible (public or at least package-private) no-arg constructor.
- Add an explicit no-arg constructor or mark one as accessible.
- For Kotlin, annotate a no-arg constructor requirement or provide a JVM-friendly default constructor.
Example fix
// before
public class LockableImpl {
public LockableImpl(boolean locked) { ... } // no no-arg ctor -> error 119
}
new DelegatePerTargetObjectIntroductionInterceptor(LockableImpl.class, Lockable.class);
// after
public class LockableImpl {
public LockableImpl() { this(false); }
public LockableImpl(boolean locked) { ... }
} Defensive patterns
Strategy: validation
Validate before calling
try {
ReflectionUtils.accessibleConstructor(defaultImplType).newInstance();
} catch (Exception ex) {
throw new IllegalArgumentException("defaultImplType needs an accessible no-arg ctor", ex);
} Type guard
boolean hasAccessibleNoArgCtor(Class<?> type) {
if (type == null || type.isInterface() || Modifier.isAbstract(type.getModifiers())) return false;
try { ReflectionUtils.accessibleConstructor(type); return true; }
catch (NoSuchMethodException e) { return false; }
} Prevention
- Give delegate classes an accessible no-arg constructor.
- Do not pass abstract classes or interfaces as defaultImplType.
- Add a startup test that instantiates the default impl type.
When it happens
Trigger: new DelegatePerTargetObjectIntroductionInterceptor(NoDefaultCtorImpl.class, Lockable.class) where NoDefaultCtorImpl has no public/accessible no-arg constructor, or passing an abstract class / interface as defaultImplType.
Common situations: Delegate class with only parameterised constructors; private no-arg constructor; accidentally passing the interface as defaultImplType; Kotlin class without a no-arg constructor.
Related errors
- Spring AOP cannot handle constructor advice
- 'defaultImpl' attribute must be set on DeclareParents
- DynamicIntroductionAdvice may only be added as part of Intro
- Both 'constructorArgs' and 'constructorArgTypes' need to be
- Number of 'constructorArgs' ({constructorArgs.length}) must
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/31f883517c9f8b98.json.
Report an issue: GitHub.