theonedev/onedev · error · ValidationException

Type not supported for unwrapping: {type}

Error message

Type not supported for unwrapping: {type}

What it means

ValidatorImpl.unwrap(Class) per the Bean Validation spec returns the underlying provider-specific type when supported; ValidatorImpl only supports unwrapping to Validator (itself). Requesting any other type throws "Type not supported for unwrapping" (IllegalArgumentException).

Source

Thrown at server-core/src/main/java/org/hibernate/validator/internal/engine/ValidatorImpl.java:347

		return validationContext.getFailingConstraints();
	}

	@Override
	public final BeanDescriptor getConstraintsForClass(Class<?> clazz) {
		return beanMetaDataManager.getBeanMetaData( clazz ).getBeanDescriptor();
	}

	@Override
	public final <T> T unwrap(Class<T> type) {
		//allow unwrapping into public super types; intentionally not exposing the
		//fact that ExecutableValidator is implemented by this class as well as this
		//might change
		if ( type.isAssignableFrom( Validator.class ) ) {
			return type.cast( this );
		}

		throw LOG.getTypeNotSupportedForUnwrappingException( type );
	}

	@Override
	public ExecutableValidator forExecutables() {
		return this;
	}

	private ValidationContextBuilder getValidationContextBuilder() {
		return new ValidationContextBuilder(
				constraintValidatorManager,
				constraintValidatorFactory,
				validatorScopedContext,
				TraversableResolvers.wrapWithCachingForSingleValidation( traversableResolver, validatorScopedContext.isTraversableResolverResultCacheEnabled() ),
				constraintValidatorInitializationContext
		);
	}

	private void sanityCheckPropertyPath(String propertyName) {

View on GitHub (pinned to d44925c47c)

Solutions

  1. Unwrap to javax.validation.Validator or HibernateValidator's concrete Validator class if provider internals are needed
  2. Remove the unwrap call and use only the standard Validator API
  3. Check provider capabilities before unwrap

Example fix

// before
MyValidatorImpl impl = validator.unwrap(MyValidatorImpl.class);
// after
org.hibernate.validator.HibernateValidator hv = validator.unwrap(org.hibernate.validator.HibernateValidator.class);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!org.hibernate.validator.HibernateValidator.class.isAssignableFrom(targetType)) { throw new IllegalArgumentException("Unsupported unwrap type: " + targetType); }

Type guard

boolean isUnwrappable(Class<?> t) { return t != null && t.isAssignableFrom(javax.validation.Validator.class); }

Try / catch

try { return validator.unwrap(type); } catch (IllegalArgumentException e) { return validator; }

Prevention

When it happens

Trigger: Calling validator.unwrap(SomeProviderSpecificClass.class) where SomeProviderSpecificClass is not the Hibernate Validator implementation itself, e.g. trying to unwrap to a custom class or to the wrong provider's type.

Common situations: Porting code between Bean Validation providers (e.g. from Apache BVal to Hibernate Validator) and keeping provider-specific unwrap calls; attempting to access provider internals.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/bd435b2543bb95ec. Report an issue: GitHub.