{"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/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java#L90-L126","documentation":"Thrown as BeanInstantiationException by the deprecated BeanUtils.instantiate(Class) when Class.newInstance() raises InstantiationException, which indicates the class cannot be instantiated reflectively — typically because it is abstract, an array, a primitive, or has no accessible no-arg constructor. The message is a hint rather than the literal cause.","triggerScenarios":"BeanUtils.instantiate(AbstractType.class) on an abstract class, or on a class without a public no-arg constructor, via the deprecated instantiate() at BeanUtils.java:107-109.","commonSituations":"Loading a 'strategy' class by name that is declared abstract; a base class configured where a subclass was intended; missing no-arg constructor after a refactor added a required-args constructor.","solutions":["Use a concrete subclass instead of the abstract base class.","Add a public no-arg constructor to the class.","Migrate to BeanUtils.instantiateClass(Constructor, args) or instantiateClass(Class) and supply a concrete type.","Verify the configured class name points at a non-abstract implementation."],"exampleFix":"// before\nBeanUtils.instantiate(AbstractRepository.class); // abstract -> InstantiationException\n\n// after\nBeanUtils.instantiateClass(JdbcRepository.class); // concrete subclass","handlingStrategy":"type-guard","validationCode":"if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) {\n  // reject or substitute a concrete subclass\n}","typeGuard":"public static boolean isConcrete(Class<?> c) {\n  return c != null && !c.isInterface() && !Modifier.isAbstract(c.getModifiers());\n}","tryCatchPattern":"try { BeanUtils.instantiate(clazz); }\ncatch (BeanInstantiationException e) {\n  if (e.getMessage().contains(\"abstract\")) { /* resolve a concrete subclass */ }\n}","preventionTips":["Ensure configured classes are concrete, not abstract.","Add a public no-arg constructor when introducing required-args constructors.","Prefer instantiateClass(Class) over the deprecated instantiate(Class)."],"tags":["spring-beans","beanutils","instantiation","abstract-class","deprecated"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}