{"id":"31f883517c9f8b98","repo":"spring-projects/spring-framework","slug":"cannot-create-default-implementation-for-interfa","errorCode":null,"errorMessage":"Cannot create default implementation for '{interfaceType.getName()}' mixin ({defaultImplType.getName()}): {ex}","messagePattern":"Cannot create default implementation for '(.+?)' mixin \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.java","lineNumber":139,"sourceCode":"\tprivate Object getIntroductionDelegateFor(@Nullable Object targetObject) {\n\t\tsynchronized (this.delegateMap) {\n\t\t\tif (this.delegateMap.containsKey(targetObject)) {\n\t\t\t\treturn this.delegateMap.get(targetObject);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tObject delegate = createNewDelegate();\n\t\t\t\tthis.delegateMap.put(targetObject, delegate);\n\t\t\t\treturn delegate;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate Object createNewDelegate() {\n\t\ttry {\n\t\t\treturn ReflectionUtils.accessibleConstructor(this.defaultImplType).newInstance();\n\t\t}\n\t\tcatch (Throwable ex) {\n\t\t\tthrow new IllegalArgumentException(\"Cannot create default implementation for '\" +\n\t\t\t\t\tthis.interfaceType.getName() + \"' mixin (\" + this.defaultImplType.getName() + \"): \" + ex);\n\t\t}\n\t}\n\n}\n","sourceCodeStart":121,"sourceCodeEnd":145,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.java#L121-L145","documentation":"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.","triggerScenarios":"new DelegatePerTargetObjectIntroductionInterceptor(NoDefaultCtorImpl.class, Lockable.class) where NoDefaultCtorImpl has no public/accessible no-arg constructor, or passing an abstract class / interface as defaultImplType.","commonSituations":"Delegate class with only parameterised constructors; private no-arg constructor; accidentally passing the interface as defaultImplType; Kotlin class without a no-arg constructor.","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."],"exampleFix":"// before\npublic class LockableImpl {\n  public LockableImpl(boolean locked) { ... } // no no-arg ctor -> error 119\n}\nnew DelegatePerTargetObjectIntroductionInterceptor(LockableImpl.class, Lockable.class);\n\n// after\npublic class LockableImpl {\n  public LockableImpl() { this(false); }\n  public LockableImpl(boolean locked) { ... }\n}","handlingStrategy":"validation","validationCode":"try {\n    ReflectionUtils.accessibleConstructor(defaultImplType).newInstance();\n} catch (Exception ex) {\n    throw new IllegalArgumentException(\"defaultImplType needs an accessible no-arg ctor\", ex);\n}","typeGuard":"boolean hasAccessibleNoArgCtor(Class<?> type) {\n    if (type == null || type.isInterface() || Modifier.isAbstract(type.getModifiers())) return false;\n    try { ReflectionUtils.accessibleConstructor(type); return true; }\n    catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["spring-aop","introduction","instantiation","constructor"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}