{"record":{"id":"d18d0ce6b4ed9c0c","repo":"pentaho/pentaho-kettle","slug":"error-initializing-userdefinedjavaclass-to-get-fields","errorCode":null,"errorMessage":"Error initializing UserDefinedJavaClass to get fields: ","messagePattern":"Error initializing UserDefinedJavaClass to get fields: ","errorType":"exception","errorClass":"KettleStepException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/userdefinedjavaclass/UserDefinedJavaClassMeta.java","lineNumber":474,"sourceCode":"    }\n  }\n\n  @Override\n  public void searchInfoAndTargetSteps( List<StepMeta> steps ) {\n    for ( InfoStepDefinition stepDefinition : infoStepDefinitions ) {\n      stepDefinition.stepMeta = StepMeta.findStep( steps, stepDefinition.stepName );\n    }\n    for ( TargetStepDefinition stepDefinition : targetStepDefinitions ) {\n      stepDefinition.stepMeta = StepMeta.findStep( steps, stepDefinition.stepName );\n    }\n  }\n\n  @Override\n  public void getFields( Bowl bowl, RowMetaInterface row, String originStepname, RowMetaInterface[] info, StepMeta nextStep,\n    VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {\n    if ( !checkClassCookings( getLog() ) ) {\n      if ( cookErrors.size() > 0 ) {\n        throw new KettleStepException( \"Error initializing UserDefinedJavaClass to get fields: \", cookErrors\n          .get( 0 ) );\n      } else {\n        return;\n      }\n    }\n\n    try {\n      Method getFieldsMethod =\n        cookedTransformClass.getMethod(\n          \"getFields\", boolean.class, RowMetaInterface.class, String.class, RowMetaInterface[].class,\n          StepMeta.class, VariableSpace.class, List.class );\n      getFieldsMethod.invoke(\n        null, isClearingResultFields(), row, originStepname, info, nextStep, space, getFieldInfo() );\n    } catch ( Exception e ) {\n      throw new KettleStepException( \"Error executing UserDefinedJavaClass.getFields(): \", e );\n    }\n  }\n","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/userdefinedjavaclass/UserDefinedJavaClassMeta.java#L456-L492","documentation":"Thrown from UserDefinedJavaClassMeta.getFields() when the Java class compiled for the UDJC step failed to 'cook' (compile/initialize). The step cannot determine its output row fields because its generated class failed initialization; the first recorded cook error is attached as the cause. This aborts transformation initialization/field propagation for the step.","triggerScenarios":"Calling getFields (during transformation init or field preview) after checkClassCookings returned false, i.e. the step's generated Java class failed to compile or its init()/main snippet threw during class cooking; cookErrors is non-empty so the first error is wrapped.","commonSituations":"Syntax errors or typos in code snippets typed into the UDJC dialog; referencing fields/variables that don't exist; using imports not on the classpath; code that throws in transformClass init; pasting code from older Pentaho versions against changed APIs.","solutions":["Read the wrapped cause (cookErrors.get(0)) — it contains the actual compile/init error and line; fix the code snippet accordingly.","Compile the snippet logic in a plain Java file outside Kettle to find syntax/typing errors quickly.","Remove or fix unsupported imports/classes; ensure all referenced fields exist on the input row and TransformData/TransformClassBase members are used correctly.","Simplify: temporarily replace snippets with a minimal valid implementation to isolate the failing snippet.","Check Pentaho/kettle-core versions match the code examples (APIs changed between versions)."],"exampleFix":"// before (snippet referencing non-existent field)\nObject v = get(Fields.In, \"custName\");\n// after\nif (data.indexOfCustName < 0) { data.indexOfCustName = getInputRowMeta().indexOfValue(\"custName\"); }\nObject v = data.indexOfCustName >= 0 ? get(Fields.In, \"custName\") : null;","handlingStrategy":"try-catch","validationCode":"// Before running, check UDJC snippets compile logically:\nfor (UserDefinedJavaClassMeta.FieldInfo fi : meta.getFieldInfo()) {\n  if (Utils.isEmpty(fi.getCode())) throw new IllegalStateException(\"UDJC snippet empty: \" + fi.getFieldName());\n}\n// Ensure imports/classes used exist on classpath","typeGuard":null,"tryCatchPattern":"try {\n  transMeta.getFields(...); // or trans.execute\n} catch (KettleStepException e) {\n  if (e.getMessage().startsWith(\"Error initializing UserDefinedJavaClass\")) {\n    Throwable cause = e.getCause(); // read real compile error\n    logError(\"UDJC cook failure: \" + cause.getMessage());\n  }\n}","preventionTips":["Test snippets in a plain Java compiler before pasting into UDJC","Keep snippets minimal; prefer dedicated steps over complex UDJC code","Pin the Pentaho version and match code examples to its API","Always inspect the cause chain, not just the wrapper message"],"tags":["kettle","udjc","class-compilation","step-init"],"backgroundTag":"module-init-failed","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"}