{"record":{"id":"4e58c3b750f8b044","repo":"pentaho/pentaho-kettle","slug":"constructor-not-found-for","errorCode":null,"errorMessage":"Constructor not found for ","messagePattern":"Constructor not found for ","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/core/injection/bean/BeanInjector.java","lineNumber":342,"sourceCode":"      }\n    }\n    return true;\n  }\n\n  private Object createObject( Class<?> clazz, Object root ) throws KettleException {\n    try {\n      // Object can be inner of metadata class. In this case constructor will require parameter\n      for ( Constructor<?> c : clazz.getConstructors() ) {\n        if ( c.getParameterTypes().length == 0 ) {\n          return clazz.newInstance();\n        } else if ( c.getParameterTypes().length == 1 && c.getParameterTypes()[0].isAssignableFrom( info.clazz ) ) {\n          return c.newInstance( root );\n        }\n      }\n    } catch ( Throwable ex ) {\n      throw new KettleException( \"Can't create object \" + clazz, ex );\n    }\n    throw new KettleException( \"Constructor not found for \" + clazz );\n  }\n\n  private Object extendArray( BeanLevelInfo s, Object obj, int newSize ) throws Exception {\n    Object existArray = s.field.get( obj );\n    if ( existArray == null ) {\n      existArray = Array.newInstance( s.leafClass, newSize );\n      s.field.set( obj, existArray );\n    }\n    int existSize = Array.getLength( existArray );\n    if ( existSize < newSize ) {\n      Object newSized = Array.newInstance( s.leafClass, newSize );\n      System.arraycopy( existArray, 0, newSized, 0, existSize );\n      existArray = newSized;\n      s.field.set( obj, existArray );\n    }\n\n    return existArray;\n  }","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/core/injection/bean/BeanInjector.java#L324-L360","documentation":"Companion to 'Can't create object': after scanning the constructors of the target class, createObject() found no no-arg constructor and no single-arg constructor accepting the root, and throws this KettleException.","triggerScenarios":"Reflection-based instantiation of a nested injection-path class where only constructors with incompatible signatures exist (e.g. required extra parameters).","commonSituations":"Value objects with builder-only construction; classes requiring DI-injected dependencies; Kotlin/Java classes with mandatory constructor args.","solutions":["Add a public no-arg constructor","Add a public constructor whose single parameter type is assignable from the root class","Change the injection property type to a class with a supported constructor"],"exampleFix":"// before\nclass Child { public Child(String mandatory){...} }\n// after\nclass Child { public Child(){...} public Child(String mandatory){...} }","handlingStrategy":"validation","validationCode":"// Same constructor-shape check as the create-failure variant\nboolean hasCtor = Arrays.stream(targetClass.getConstructors()).anyMatch(k ->\n  k.getParameterCount() == 0\n  || (k.getParameterCount() == 1 && k.getParameterTypes()[0].isAssignableFrom(rootClass)));\nif (!hasCtor) throw new IllegalStateException(\"Constructor not found for \" + targetClass);","typeGuard":"static boolean hasSupportedConstructor(Class<?> c, Class<?> root) {\n  try { c.getDeclaredConstructor(); return true; }\n  catch (NoSuchMethodException e) {\n    return Arrays.stream(c.getConstructors()).anyMatch(k ->\n      k.getParameterCount() == 1 && k.getParameterTypes()[0].isAssignableFrom(root));\n  }\n}","tryCatchPattern":"try {\n  injector.injectValue(bean, path, value);\n} catch (KettleException e) {\n  if (e.getMessage().startsWith(\"Constructor not found\")) {\n    log.error(\"Add a no-arg or root-arg constructor for: \" + e.getMessage(), e);\n  } else throw e;\n}","preventionTips":["Mandatory-arg classes need an extra no-arg or root-arg constructor to participate in injection","Cover nested bean instantiation in injection tests"],"tags":["reflection","constructor","bean-injection"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}