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) 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.

Solutions

  1. Use instantiateClass(Class) which gives better diagnostics and tries primary/default constructors.
  2. Replace the abstract/primitive/array class argument with a concrete instantiable subclass.
  3. Add a concrete subclass or ensure the configured class name points to an instantiable type.
  4. If it must be abstract-with-subclass, resolve the concrete type via a factory/lookup first.

Example fix

// before
BeanUtils.instantiate(AbstractRepository.class); // abstract

// after
BeanUtils.instantiateClass(JdbcRepository.class); // concrete
Defensive patterns

Strategy: validation

Validate before calling

if (!clazz.isInterface() && !Modifier.isAbstract(clazz.getModifiers())
        && !clazz.isPrimitive() && !clazz.isArray()) {
    BeanUtils.instantiate(clazz);
}

Type guard

static boolean concreteNonArray(Class<?> c) {
    return !c.isInterface() && !Modifier.isAbstract(c.getModifiers())
        && !c.isPrimitive() && !c.isArray() && c != void.class;
}

Try / catch

try {
    BeanUtils.instantiate(clazz);
} catch (BeanInstantiationException ex) {
    if (ex.getCause() instanceof InstantiationException) {
        // abstract/array/primitive -> pick a concrete subclass
    } else throw ex;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09). Data as JSON: /api/errors/f0d41316c2d3eaf9. Report an issue: GitHub.

Appendix: 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 definition

View on GitHub (pinned to 69bf83ad71)