pentaho/pentaho-kettle · error · KettleStepException

Error initializing UserDefinedJavaClass to get fields:

Error message

Error initializing UserDefinedJavaClass to get fields: 

What it means

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.

Solutions

  1. Read the wrapped cause (cookErrors.get(0)) — it contains the actual compile/init error and line; fix the code snippet accordingly.
  2. Compile the snippet logic in a plain Java file outside Kettle to find syntax/typing errors quickly.
  3. Remove or fix unsupported imports/classes; ensure all referenced fields exist on the input row and TransformData/TransformClassBase members are used correctly.
  4. Simplify: temporarily replace snippets with a minimal valid implementation to isolate the failing snippet.
  5. Check Pentaho/kettle-core versions match the code examples (APIs changed between versions).

Example fix

// before (snippet referencing non-existent field)
Object v = get(Fields.In, "custName");
// after
if (data.indexOfCustName < 0) { data.indexOfCustName = getInputRowMeta().indexOfValue("custName"); }
Object v = data.indexOfCustName >= 0 ? get(Fields.In, "custName") : null;
Defensive patterns

Strategy: try-catch

Validate before calling

// Before running, check UDJC snippets compile logically:
for (UserDefinedJavaClassMeta.FieldInfo fi : meta.getFieldInfo()) {
  if (Utils.isEmpty(fi.getCode())) throw new IllegalStateException("UDJC snippet empty: " + fi.getFieldName());
}
// Ensure imports/classes used exist on classpath

Try / catch

try {
  transMeta.getFields(...); // or trans.execute
} catch (KettleStepException e) {
  if (e.getMessage().startsWith("Error initializing UserDefinedJavaClass")) {
    Throwable cause = e.getCause(); // read real compile error
    logError("UDJC cook failure: " + cause.getMessage());
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/d18d0ce6b4ed9c0c. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/userdefinedjavaclass/UserDefinedJavaClassMeta.java:474

    }
  }

  @Override
  public void searchInfoAndTargetSteps( List<StepMeta> steps ) {
    for ( InfoStepDefinition stepDefinition : infoStepDefinitions ) {
      stepDefinition.stepMeta = StepMeta.findStep( steps, stepDefinition.stepName );
    }
    for ( TargetStepDefinition stepDefinition : targetStepDefinitions ) {
      stepDefinition.stepMeta = StepMeta.findStep( steps, stepDefinition.stepName );
    }
  }

  @Override
  public void getFields( Bowl bowl, RowMetaInterface row, String originStepname, RowMetaInterface[] info, StepMeta nextStep,
    VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
    if ( !checkClassCookings( getLog() ) ) {
      if ( cookErrors.size() > 0 ) {
        throw new KettleStepException( "Error initializing UserDefinedJavaClass to get fields: ", cookErrors
          .get( 0 ) );
      } else {
        return;
      }
    }

    try {
      Method getFieldsMethod =
        cookedTransformClass.getMethod(
          "getFields", boolean.class, RowMetaInterface.class, String.class, RowMetaInterface[].class,
          StepMeta.class, VariableSpace.class, List.class );
      getFieldsMethod.invoke(
        null, isClearingResultFields(), row, originStepname, info, nextStep, space, getFieldInfo() );
    } catch ( Exception e ) {
      throw new KettleStepException( "Error executing UserDefinedJavaClass.getFields(): ", e );
    }
  }

View on GitHub (pinned to f3058517a1)