{"record":{"id":"f0d41316c2d3eaf9","repo":"spring-projects/spring-framework","slug":"is-it-an-abstract-class","errorCode":null,"errorMessage":"Is it an abstract class?","messagePattern":"Is it an abstract class\\?","errorType":"exception","errorClass":"BeanInstantiationException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/BeanUtils.java","lineNumber":108,"sourceCode":"\t/**\n\t * Convenience method to instantiate a class using its no-arg constructor.\n\t * @param clazz class to instantiate\n\t * @return the new instance\n\t * @throws BeanInstantiationException if the bean cannot be instantiated\n\t * @see Class#newInstance()\n\t * @deprecated following the deprecation of {@link Class#newInstance()} in JDK 9\n\t */\n\t@Deprecated(since = \"5.0\")\n\tpublic static <T> T instantiate(Class<T> clazz) throws BeanInstantiationException {\n\t\tAssert.notNull(clazz, \"Class must not be null\");\n\t\tif (clazz.isInterface()) {\n\t\t\tthrow new BeanInstantiationException(clazz, \"Specified class is an interface\");\n\t\t}\n\t\ttry {\n\t\t\treturn clazz.newInstance();\n\t\t}\n\t\tcatch (InstantiationException ex) {\n\t\t\tthrow new BeanInstantiationException(clazz, \"Is it an abstract class?\", ex);\n\t\t}\n\t\tcatch (IllegalAccessException ex) {\n\t\t\tthrow new BeanInstantiationException(clazz, \"Is the constructor accessible?\", ex);\n\t\t}\n\t}\n\n\t/**\n\t * Instantiate a class using its 'primary' constructor (for Kotlin classes,\n\t * potentially having default arguments declared) or its default constructor\n\t * (for regular Java classes, expecting a standard no-arg setup).\n\t * <p>Note that this method tries to set the constructor accessible\n\t * if given a non-accessible (that is, non-public) constructor.\n\t * @param clazz the class to instantiate\n\t * @return the new instance\n\t * @throws BeanInstantiationException if the bean cannot be instantiated.\n\t * The cause may notably indicate a {@link NoSuchMethodException} if no\n\t * primary/default constructor was found, a {@link NoClassDefFoundError}\n\t * or other {@link LinkageError} in case of an unresolvable class definition","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java#L90-L126","documentation":"Thrown as BeanInstantiationException by the deprecated BeanUtils.instantiate(Class) at BeanUtils.java:108 when Class.newInstance() raises InstantiationException. This happens for classes the JVM cannot instantiate reflectively: abstract classes, array types, primitive/void classes, or classes with no accessible no-arg constructor that the JVM rejects at this stage. The message is a diagnostic hint rather than the literal cause.","triggerScenarios":"Calling the deprecated BeanUtils.instantiate(Class) with an abstract class, an array class (String[].class), a primitive class (int.class), void.class, or a class lacking a parameterless constructor that newInstance() cannot satisfy.","commonSituations":"Loading a strategy class by name that turns out to be abstract; passing an array or primitive Class object by mistake; legacy instantiation of a base class instead of a subclass; Spring XML <bean class=\"...AbstractBase\"/> misconfiguration reaching deprecated paths.","solutions":["Use instantiateClass(Class) which gives better diagnostics and tries primary/default constructors.","Replace the abstract/primitive/array class argument with a concrete instantiable subclass.","Add a concrete subclass or ensure the configured class name points to an instantiable type.","If it must be abstract-with-subclass, resolve the concrete type via a factory/lookup first."],"exampleFix":"// before\nBeanUtils.instantiate(AbstractRepository.class); // abstract\n\n// after\nBeanUtils.instantiateClass(JdbcRepository.class); // concrete","handlingStrategy":"validation","validationCode":"if (!clazz.isInterface() && !Modifier.isAbstract(clazz.getModifiers())\n        && !clazz.isPrimitive() && !clazz.isArray()) {\n    BeanUtils.instantiate(clazz);\n}","typeGuard":"static boolean concreteNonArray(Class<?> c) {\n    return !c.isInterface() && !Modifier.isAbstract(c.getModifiers())\n        && !c.isPrimitive() && !c.isArray() && c != void.class;\n}","tryCatchPattern":"try {\n    BeanUtils.instantiate(clazz);\n} catch (BeanInstantiationException ex) {\n    if (ex.getCause() instanceof InstantiationException) {\n        // abstract/array/primitive -> pick a concrete subclass\n    } else throw ex;\n}","preventionTips":["Use instantiateClass(Class) which gives clearer errors and supports default/primary constructors.","Reject abstract, array, primitive, and void classes before instantiation.","Configure concrete subclass names in external config rather than base classes.","Add a unit test that instantiates each configured class name."],"tags":["spring-beans","beanutils","instantiation","abstract","deprecated"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}