theonedev/onedev · error · IllegalArgumentException

The group must not be null.

Error message

The group must not be null.

What it means

ValidatorImpl.sanityCheckGroups enforces the Bean Validation contract that the groups array must not be null and must not contain null elements. Passing a null groups array or a null group class throws "The group must not be null." (IllegalArgumentException).

Source

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

				constraintValidatorManager,
				constraintValidatorFactory,
				validatorScopedContext,
				TraversableResolvers.wrapWithCachingForSingleValidation( traversableResolver, validatorScopedContext.isTraversableResolverResultCacheEnabled() ),
				constraintValidatorInitializationContext
		);
	}

	private void sanityCheckPropertyPath(String propertyName) {
		if ( propertyName == null || propertyName.length() == 0 ) {
			throw LOG.getInvalidPropertyPathException();
		}
	}

	private void sanityCheckGroups(Class<?>[] groups) {
		Contracts.assertNotNull( groups, MESSAGES.groupMustNotBeNull() );
		for ( Class<?> clazz : groups ) {
			if ( clazz == null ) {
				throw new IllegalArgumentException( MESSAGES.groupMustNotBeNull() );
			}
		}
	}

	private ValidationOrder determineGroupValidationOrder(Class<?>[] groups) {
		Collection<Class<?>> resultGroups;
		// if no groups is specified use the default
		if ( groups.length == 0 ) {
			resultGroups = DEFAULT_GROUPS;
		}
		else {
			resultGroups = Arrays.asList( groups );
		}
		return validationOrderGenerator.getValidationOrder( resultGroups );
	}

	/**
	 * Validates the given object using the available context information.

View on GitHub (pinned to d44925c47c)

Solutions

  1. Pass an empty array or Default.class instead of null groups
  2. Filter null entries out of dynamically built group arrays
  3. Assert group classes are non-null before invoking the validator

Example fix

// before
validator.validate(bean, groups); // groups may be null
// after
Class<?>[] safeGroups = groups == null ? new Class<?>[]{javax.validation.groups.Default.class}
        : java.util.Arrays.stream(groups).filter(java.util.Objects::nonNull).toArray(Class<?>[]::new);
validator.validate(bean, safeGroups);
Defensive patterns

Strategy: validation

Validate before calling

if (groups == null) throw new IllegalArgumentException("groups required"); for (Class<?> g : groups) if (g == null) throw new IllegalArgumentException("null group element");

Type guard

boolean hasNoNullGroups(Class<?>[] gs) { return gs != null && java.util.Arrays.stream(gs).allMatch(java.util.Objects::nonNull); }

Try / catch

try { validator.validate(bean, groups); } catch (IllegalArgumentException e) { log.warn("Invalid validation groups", e); validator.validate(bean); }

Prevention

When it happens

Trigger: Calling validate/validateProperty/validateValue/validateParameters/validateReturnValue with groups == null, or an array like new Class<?>[]{Default.class, null} built dynamically.

Common situations: Building group arrays from configuration or annotations where some entries resolve to null; reflection code appending a null class; varargs calls with a null Class value.

Related errors


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