hibernate/hibernate-orm · error · IllegalArgumentException

Passed `component` for function return cannot be null

Error message

Passed `component` for function return cannot be null

What it means

withComponent(component, resolver) is the funnel every invariant()/useArgType() call on SetReturningFunctionTypeResolverBuilder passes through; it keys the resolver map by component name and rejects a null component with IllegalArgumentException. Any builder call whose first argument is null therefore fails at registration time, before the function is ever executed.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/internal/SetReturningFunctionTypeResolverBuilder.java:82

			throw new IllegalArgumentException( "Passed `invariantType` for function return cannot be null" );
		}
		if ( selectionExpression == null ) {
			throw new IllegalArgumentException( "Passed `selectionExpression` for function return cannot be null" );
		}
		return withComponent( component, new BasicTypeTypeResolver( component, selectionExpression, invariantType ) );
	}

	@Override
	public SetReturningFunctionTypeResolverBuilder useArgType(String component, int argPosition, String selectionExpression) {
		if ( selectionExpression == null ) {
			throw new IllegalArgumentException( "Passed `selectionExpression` for function return cannot be null" );
		}
		return withComponent( component, new ArgTypeTypeResolver( component, selectionExpression, argPosition ) );
	}

	private SetReturningFunctionTypeResolverBuilder withComponent(String component, TypeResolver resolver) {
		if ( component == null ) {
			throw new IllegalArgumentException( "Passed `component` for function return cannot be null" );
		}
		typeResolvers.put( component, resolver );
		return this;
	}

	@Override
	public SetReturningFunctionTypeResolver build() {
		return new SetReturningFunctionTypeResolverImpl( this );
	}

	private static class SetReturningFunctionTypeResolverImpl implements SetReturningFunctionTypeResolver {

		private final TypeResolver[] typeResolvers;

		public SetReturningFunctionTypeResolverImpl(SetReturningFunctionTypeResolverBuilder builder) {
			this.typeResolvers = builder.typeResolvers.values().toArray( new TypeResolver[0] );
		}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Pass a stable, non-null component name - it identifies the row component of the set-returning function.
  2. If the name comes from configuration, validate it early: Objects.requireNonNull(name, "component").
  3. Also reject empty/blank names; they are technically accepted but produce confusing result mappings.

Example fix

// before
String name = config.get("component"); // null
builder.invariant(name, StandardBasicTypes.STRING, name);

// after
String name = Objects.requireNonNull(config.get("component"), "component");
builder.invariant(name, StandardBasicTypes.STRING, name);
Defensive patterns

Strategy: validation

Validate before calling

String component = Objects.requireNonNull(componentName, "component");
if (component.isBlank()) throw new IllegalArgumentException("component must not be blank");
builder.invariant(component, type, selectionExpression);

Try / catch

try {
    builder.invariant(component, type, selection);
} catch (IllegalArgumentException e) {
    throw new IllegalStateException("Incomplete set-returning function definition: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: builder.invariant(null, StandardBasicTypes.STRING, "value") or a computed component name that is null - e.g. derived from a map key, enum name, or config value that was absent.

Common situations: Component names generated from configuration or from reflection over array element types; a typo'd getter returning null; copy-pasted builder chains where the component variable is never assigned.

Related errors


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