{"record":{"id":"166d7e9eea5e2a02","repo":"chinabugotech/hutool","slug":"no-constructor-provided-166d7e","errorCode":null,"errorMessage":"No constructor provided","messagePattern":"No constructor provided","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hutool-aop/src/main/java/cn/hutool/aop/proxy/SpringCglibProxyFactory.java","lineNumber":61,"sourceCode":"\t\tClass<?>[] parameterTypes;\n\t\tObject[] values;\n\t\tIllegalArgumentException finalException = null;\n\t\tfor (final Constructor<?> constructor : constructors) {\n\t\t\tparameterTypes = constructor.getParameterTypes();\n\t\t\tvalues = ClassUtil.getDefaultValues(parameterTypes);\n\n\t\t\ttry {\n\t\t\t\treturn (T) enhancer.create(parameterTypes, values);\n\t\t\t} catch (final IllegalArgumentException e) {\n\t\t\t\t//ignore\n\t\t\t\tfinalException = e;\n\t\t\t}\n\t\t}\n\t\tif (null != finalException) {\n\t\t\tthrow finalException;\n\t\t}\n\n\t\tthrow new IllegalArgumentException(\"No constructor provided\");\n\t}\n}\n","sourceCodeStart":43,"sourceCodeEnd":64,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-aop/src/main/java/cn/hutool/aop/proxy/SpringCglibProxyFactory.java#L43-L64","documentation":"Identical logic to CglibProxyFactory but uses Spring's repackaged cglib (org.springframework.cglib.proxy.Enhancer). Selected by hutool-aop when spring-core is on the classpath. 'No constructor provided' is thrown only when the target class has zero discoverable constructors and no IllegalArgumentException was captured; the normal all-constructors-rejected case rethrows the last IllegalArgumentException instead.","triggerScenarios":"Proxying an interface, array, primitive, or synthetic class with no declared constructors via hutool-aop in a Spring environment (spring-core present, so SpringCglibProxyFactory is chosen).","commonSituations":"Spring Boot apps using hutool-aop; accidentally wrapping an interface or a CGLIB-generated Spring bean that already has unusual constructor metadata; proxying JDK dynamic proxies or lambda metafactory outputs.","solutions":["Proxy a concrete non-final class, not an interface/array/primitive.","Use JDK dynamic proxies for interface-only targets.","If proxying another proxy/synthetic bean, unwrap to the real target class first.","Confirm the target's constructors are visible to ReflectUtil.getConstructors."],"exampleFix":"// before (Spring env, spring-core on classpath)\nMyInterface p = ProxyUtil.proxy(interfaceInstance, aspect);\n// -> No constructor provided\n\n// after\nMyConcreteService p = ProxyUtil.proxy(new MyConcreteService(), aspect);","handlingStrategy":"type-guard","validationCode":"// In Spring env, guard the proxy target the same way\nClass<?> c = target.getClass();\nif (c.isInterface() || c.isArray() || c.isPrimitive()\n    || c.getDeclaredConstructors().length == 0) {\n    throw new IllegalArgumentException(\"not cglib-proxyable: \" + c);\n}","typeGuard":"static boolean isCglibProxyable(Object target) {\n    if (target == null) return false;\n    Class<?> c = target.getClass();\n    return !c.isInterface() && !c.isArray() && !c.isPrimitive()\n        && !Modifier.isFinal(c.getModifiers())\n        && c.getDeclaredConstructors().length > 0;\n}","tryCatchPattern":"try {\n    return ProxyUtil.proxy(target, aspect);\n} catch (IllegalArgumentException e) {\n    if (\"No constructor provided\".equals(e.getMessage())) {\n        // SpringCglib chosen because spring-core present; target not proxyable\n        // -> unwrap to the real target class or use JDK proxy for interfaces\n    }\n    throw e;\n}","preventionTips":["In Spring Boot, remember SpringCglibProxyFactory is auto-selected.","Proxy the concrete target class, not an interface or another proxy.","Unwrap Spring AOP proxies before re-proxying with hutool."],"tags":["aop","cglib","spring","proxy","reflection"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}