gradle/gradle · error · IllegalArgumentException
Unable to create an instance of type %s
Error message
Unable to create an instance of type %s
What it means
ManagedObjectFactory.newInstance(owner, propertyName, type, paramType) is invoked from generated managed-property code to materialize a parameterized managed value (for example the element type of a collection property). It delegates to the ManagedObjectRegistry; when no registered @ManagedObjectCreator factory can produce the (type, paramType) pair, the registry returns null and this IllegalArgumentException with the class name is thrown.
Source
Thrown at platforms/core-configuration/model-core/src/main/java/org/gradle/internal/instantiation/generator/ManagedObjectFactory.java:88
roleHandler.applyRoleTo(owner, value);
}
// Called from generated code
public Object newInstance(ModelObject owner, String propertyName, Class<?> type) {
Object providedType = getManagedObjectRegistry().newInstance(type);
if (providedType != null) {
return attachOwner(providedType, owner, propertyName);
}
return attachOwner(instantiator.newInstanceWithDisplayName(type, displayNameFor(owner, propertyName)), owner, propertyName);
}
// Called from generated code
public Object newInstance(ModelObject owner, String propertyName, Class<?> type, Class<?> paramType) {
Object providedType = getManagedObjectRegistry().newInstance(type, paramType);
if (providedType != null) {
return attachOwner(providedType, owner, propertyName);
}
throw new IllegalArgumentException("Unable to create an instance of type " + type.getName());
}
// Called from generated code
public Object newInstance(ModelObject owner, String propertyName, Class<?> type, Class<?> keyType, Class<?> valueType) {
Object providedType = getManagedObjectRegistry().newInstance(type, keyType, valueType);
if (providedType != null) {
return attachOwner(providedType, owner, propertyName);
}
throw new IllegalArgumentException("Unable to create an instance of type " + type.getName());
}
private static ManagedPropertyName displayNameFor(ModelObject owner, String propertyName) {
if (owner.getModelIdentityDisplayName() instanceof ManagedPropertyName) {
ManagedPropertyName root = (ManagedPropertyName) owner.getModelIdentityDisplayName();
return new NestedManagedPropertyName(root, propertyName);
} else {
return new RootManagedPropertyName(cachedOwnerDisplayNameOf(owner), propertyName);
}View on GitHub (pinned to 534f27719b)
Solutions
- Register an @ManagedObjectProvider service with an @ManagedObjectCreator method that creates CustomType.
- Declare the element as a managed (abstract) type in the plugin's managed schema so built-in factories apply.
- Check the paramType: built-ins cover collections of managed and standard types; custom parameterizations need explicit creators.
Example fix
// before
// managed property: List<CustomType> getRules(); — no provider registered for CustomType
// after
@ManagedObjectProvider
public class CustomTypesProvider {
@ManagedObjectCreator
public CustomType create(Class<CustomType> type) { return schema.newInstance(type); }
} Defensive patterns
Strategy: validation
Validate before calling
if (managedObjectRegistry.newInstance(type, paramType) == null) {
throw new IllegalStateException(
"no @ManagedObjectCreator for " + type.getName() + "<" + paramType.getName() + ">");
} Prevention
- Register an @ManagedObjectProvider for every custom element type used in managed collection properties.
- Prefer managed (abstract) schema types over arbitrary concrete classes inside parameterized properties.
When it happens
Trigger: A managed schema property such as List<CustomType> where CustomType has no registered creator: generated code calls this method, getManagedObjectRegistry().newInstance(type, paramType) returns null, and the exception fires.
Common situations: Adding new managed types to a software-model plugin without registering their @ManagedObjectProvider; using an arbitrary concrete class where the model requires a managed (abstract) type; parameterizing collections with unmanaged element types.
Related errors
- Could not create an instance of type %s.
- Service %s annotated with @ManagedObjectProvider must have a
- Method %s annotated with @ManagedObjectCreator must not be s
- Invalid %s: %s
- Component '{name}' not found.
AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22).
Data as JSON: /api/errors/2a7d60d93f268543.
Report an issue: GitHub.