{"record":{"id":"740c7af68dccfbd6","repo":"spring-projects/spring-framework","slug":"unable-to-instantiate-aspect-class-aspectclass-g","errorCode":null,"errorMessage":"Unable to instantiate aspect class: {aspectClass.getName()}","messagePattern":"Unable to instantiate aspect class: (.+?)","errorType":"exception","errorClass":"AopConfigException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/aspectj/SimpleAspectInstanceFactory.java","lineNumber":68,"sourceCode":"\n\t/**\n\t * Return the specified aspect class (never {@code null}).\n\t */\n\tpublic final Class<?> getAspectClass() {\n\t\treturn this.aspectClass;\n\t}\n\n\t@Override\n\tpublic final Object getAspectInstance() {\n\t\ttry {\n\t\t\treturn ReflectionUtils.accessibleConstructor(this.aspectClass).newInstance();\n\t\t}\n\t\tcatch (NoSuchMethodException ex) {\n\t\t\tthrow new AopConfigException(\n\t\t\t\t\t\"No default constructor on aspect class: \" + this.aspectClass.getName(), ex);\n\t\t}\n\t\tcatch (InstantiationException ex) {\n\t\t\tthrow new AopConfigException(\n\t\t\t\t\t\"Unable to instantiate aspect class: \" + this.aspectClass.getName(), ex);\n\t\t}\n\t\tcatch (IllegalAccessException | InaccessibleObjectException ex) {\n\t\t\tthrow new AopConfigException(\n\t\t\t\t\t\"Could not access aspect constructor: \" + this.aspectClass.getName(), ex);\n\t\t}\n\t\tcatch (InvocationTargetException ex) {\n\t\t\tthrow new AopConfigException(\n\t\t\t\t\t\"Failed to invoke aspect constructor: \" + this.aspectClass.getName(), ex.getTargetException());\n\t\t}\n\t}\n\n\t@Override\n\tpublic @Nullable ClassLoader getAspectClassLoader() {\n\t\treturn this.aspectClass.getClassLoader();\n\t}\n\n\t/**","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/aspectj/SimpleAspectInstanceFactory.java#L50-L86","documentation":"Thrown when accessibleConstructor().newInstance() raises InstantiationException — the aspect class is abstract, an interface, an array class, a primitive type, or void. These types cannot be instantiated at all, so the factory cannot produce an aspect instance.","triggerScenarios":"Passing AbstractAspect.class, an interface, or a primitive/array class to SimpleAspectInstanceFactory — e.g. new SimpleAspectInstanceFactory(AbstractBaseAspect.class).","commonSituations":"Accidentally pointing the factory at an abstract base aspect class, or passing the wrong Class reference (e.g., an interface type instead of the concrete implementation).","solutions":["Pass a concrete (non-abstract, non-interface) aspect class","Verify the class is a real instantiable class — not an interface, array, primitive, or abstract type","Choose an AspectInstanceFactory implementation appropriate for the aspect's lifecycle"],"exampleFix":"// before\nnew SimpleAspectInstanceFactory(AbstractBaseAspect.class); // throws: abstract\n\n// after\nnew SimpleAspectInstanceFactory(ConcreteAspect.class); // concrete subclass","handlingStrategy":"validation","validationCode":"// Validate the class is concrete and instantiable\nint mods = aspectClass.getModifiers();\nif (Modifier.isAbstract(mods) || Modifier.isInterface(mods) || aspectClass.isArray() || aspectClass.isPrimitive()) {\n    throw new IllegalStateException(\n        \"Cannot instantiate \" + aspectClass.getName() + \": it is abstract, an interface, or a non-class type\");\n}\nnew SimpleAspectInstanceFactory(aspectClass);","typeGuard":null,"tryCatchPattern":"try {\n    factory.getAspectInstance();\n} catch (AopConfigException ex) {\n    if (ex.getMessage().contains(\"Unable to instantiate\")) {\n        // Use a concrete subclass instead\n    }\n    throw ex;\n}","preventionTips":["Pass only concrete, non-abstract, non-interface aspect classes to SimpleAspectInstanceFactory","Double-check the Class reference is the concrete implementation, not a base class or interface"],"tags":["spring-aop","aspectj","aspect-instantiation"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}