hibernate/hibernate-orm · error · IllegalArgumentException

Cannot erase type: " + type

Error message

Cannot erase type: " + type

What it means

Error "Cannot erase type: " + type" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/internal/util/GenericsHelper.java:146

	 * @return The erased type
	 */
	public static Class<?> erasedType(Type type) {
		if ( type instanceof Class<?> clazz ) {
			return clazz;
		}
		else if ( type instanceof ParameterizedType parameterizedType ) {
			return erasedType( parameterizedType.getRawType() );
		}
		else if ( type instanceof TypeVariable<?> typeVariable ) {
			return erasedType( typeVariable.getBounds()[0] );
		}
		else if ( type instanceof GenericArrayType genericArrayType ) {
			return genericArrayType.getGenericComponentType() instanceof Class<?> elementClass
					? elementClass.arrayType()
					: Object[].class;
		}
		else {
			throw new IllegalArgumentException( "Cannot erase type: " + type );
		}
	}

	/**
	 * Get the type argument of the instantiation of the given generic
	 * type constructor which is a supertype of the given type expression.
	 * @param genericType A generic type constructor
	 * @param implementingType A type expression
	 * @return The type arguments assigned to parameters of the generic type constructor
	 */
	public static Type[] typeArguments(Class<?> genericType, Type implementingType) {
		if ( genericType.getTypeParameters().length == 0 ) {
			return EMPTY_TYPE_ARRAY;
		}
		else {
			final var instantiation =
					supertypeInstantiation( genericType, implementingType );
			if ( instantiation == null ) {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Pass a Class, ParameterizedType, or GenericArrayType to erase(); other Type kinds (wildcards, type variables) cannot be erased directly.

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/internal/util/GenericsHelper.java:146 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/a3588dfc2fa5474a. Report an issue: GitHub.