{"record":{"id":"2a7d60d93f268543","repo":"gradle/gradle","slug":"unable-to-create-an-instance-of-type-s","errorCode":null,"errorMessage":"Unable to create an instance of type %s","messagePattern":"Unable to create an instance of type (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"platforms/core-configuration/model-core/src/main/java/org/gradle/internal/instantiation/generator/ManagedObjectFactory.java","lineNumber":88,"sourceCode":"        roleHandler.applyRoleTo(owner, value);\n    }\n\n    // Called from generated code\n    public Object newInstance(ModelObject owner, String propertyName, Class<?> type) {\n        Object providedType = getManagedObjectRegistry().newInstance(type);\n        if (providedType != null) {\n            return attachOwner(providedType, owner, propertyName);\n        }\n        return attachOwner(instantiator.newInstanceWithDisplayName(type, displayNameFor(owner, propertyName)), owner, propertyName);\n    }\n\n    // Called from generated code\n    public Object newInstance(ModelObject owner, String propertyName, Class<?> type, Class<?> paramType) {\n        Object providedType = getManagedObjectRegistry().newInstance(type, paramType);\n        if (providedType != null) {\n            return attachOwner(providedType, owner, propertyName);\n        }\n        throw new IllegalArgumentException(\"Unable to create an instance of type \" + type.getName());\n    }\n\n    // Called from generated code\n    public Object newInstance(ModelObject owner, String propertyName, Class<?> type, Class<?> keyType, Class<?> valueType) {\n        Object providedType = getManagedObjectRegistry().newInstance(type, keyType, valueType);\n        if (providedType != null) {\n            return attachOwner(providedType, owner, propertyName);\n        }\n        throw new IllegalArgumentException(\"Unable to create an instance of type \" + type.getName());\n    }\n\n    private static ManagedPropertyName displayNameFor(ModelObject owner, String propertyName) {\n        if (owner.getModelIdentityDisplayName() instanceof ManagedPropertyName) {\n            ManagedPropertyName root = (ManagedPropertyName) owner.getModelIdentityDisplayName();\n            return new NestedManagedPropertyName(root, propertyName);\n        } else {\n            return new RootManagedPropertyName(cachedOwnerDisplayNameOf(owner), propertyName);\n        }","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/gradle/gradle/blob/534f27719b66953f95cc907aae7f2c1b12f5482d/platforms/core-configuration/model-core/src/main/java/org/gradle/internal/instantiation/generator/ManagedObjectFactory.java#L70-L106","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n// managed property: List<CustomType> getRules(); — no provider registered for CustomType\n// after\n@ManagedObjectProvider\npublic class CustomTypesProvider {\n    @ManagedObjectCreator\n    public CustomType create(Class<CustomType> type) { return schema.newInstance(type); }\n}","handlingStrategy":"validation","validationCode":"if (managedObjectRegistry.newInstance(type, paramType) == null) {\n    throw new IllegalStateException(\n        \"no @ManagedObjectCreator for \" + type.getName() + \"<\" + paramType.getName() + \">\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["gradle","managed-types","managed-object-registry","software-model"],"backgroundTag":"unregistered-managed-type","analyzedSha":"534f27719b66953f95cc907aae7f2c1b12f5482d","analyzedAt":"2026-08-22T08:09:12.375Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}