spring-projects/spring-framework · error · BeanInstantiationException
Is it an abstract class?
Error message
Is it an abstract class?
What it means
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.
Source
Thrown at spring-beans/src/main/java/org/springframework/beans/BeanUtils.java:108
/**
* Convenience method to instantiate a class using its no-arg constructor.
* @param clazz class to instantiate
* @return the new instance
* @throws BeanInstantiationException if the bean cannot be instantiated
* @see Class#newInstance()
* @deprecated following the deprecation of {@link Class#newInstance()} in JDK 9
*/
@Deprecated(since = "5.0")
public static <T> T instantiate(Class<T> clazz) throws BeanInstantiationException {
Assert.notNull(clazz, "Class must not be null");
if (clazz.isInterface()) {
throw new BeanInstantiationException(clazz, "Specified class is an interface");
}
try {
return clazz.newInstance();
}
catch (InstantiationException ex) {
throw new BeanInstantiationException(clazz, "Is it an abstract class?", ex);
}
catch (IllegalAccessException ex) {
throw new BeanInstantiationException(clazz, "Is the constructor accessible?", ex);
}
}
/**
* Instantiate a class using its 'primary' constructor (for Kotlin classes,
* potentially having default arguments declared) or its default constructor
* (for regular Java classes, expecting a standard no-arg setup).
* <p>Note that this method tries to set the constructor accessible
* if given a non-accessible (that is, non-public) constructor.
* @param clazz the class to instantiate
* @return the new instance
* @throws BeanInstantiationException if the bean cannot be instantiated.
* The cause may notably indicate a {@link NoSuchMethodException} if no
* primary/default constructor was found, a {@link NoClassDefFoundError}
* or other {@link LinkageError} in case of an unresolvable class definitionView on GitHub (pinned to e8729d0438)
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.
Example fix
// before BeanUtils.instantiate(AbstractRepository.class); // abstract -> InstantiationException // after BeanUtils.instantiateClass(JdbcRepository.class); // concrete subclass
Defensive patterns
Strategy: type-guard
Validate before calling
if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) {
// reject or substitute a concrete subclass
} Type guard
public static boolean isConcrete(Class<?> c) {
return c != null && !c.isInterface() && !Modifier.isAbstract(c.getModifiers());
} Try / catch
try { BeanUtils.instantiate(clazz); }
catch (BeanInstantiationException e) {
if (e.getMessage().contains("abstract")) { /* resolve a concrete subclass */ }
} Prevention
- 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).
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Specified class is an interface
- Is the constructor accessible?
- No default constructor found
- Unresolvable class definition
- Illegal arguments for constructor
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/f0d41316c2d3eaf9.json.
Report an issue: GitHub.