pentaho/pentaho-kettle · error · KettleException
UserDefinedJavaClassDialog.Exception.CouldNotGetFields
Error message
UserDefinedJavaClassDialog.Exception.CouldNotGetFields
What it means
In UserDefinedJavaClassDialog's field-preview (test) path, getFields() on the step meta did not succeed (returned false), so a KettleException 'CouldNotGetFields' is thrown and shown in a 'Test failed' ErrorDialog. It means the UDJC step could not determine its output fields for the preview.
Solutions
- Fix compile errors in the UDJC Java code shown in the dialog (check generated code for syntax/typing mistakes).
- Ensure the step has a valid input hop and the previous step produces the expected fields.
- Check 'Fields' grid entries: referenced input field names must match actual upstream fields exactly.
- Compile a minimal version of the class (remove added code) to isolate the failing statement, then re-add incrementally.
Example fix
// before Object[] r = new Object[data.outputRowMeta.size()]; // uses wrong meta // after Object[] r = RowDataUtil.allocateRowData(data.outputRowMeta.size());
Defensive patterns
Strategy: try-catch
Validate before calling
// before testing the class, confirm input meta resolves
if (transMeta.getPrevStepFields(stepMeta) == null || transMeta.getPrevStepFields(stepMeta).isEmpty()) {
throw new KettleException("UDJC step has no input fields; connect a previous step first");
} Type guard
boolean canGetFields(TransMeta tm, StepMeta sm) { try { return tm.getStepFields(sm) != null; } catch (Exception e) { return false; } } Try / catch
try { testClass(); } catch (KettleException e) { new ErrorDialog(shell, "Test failed", "Could not get fields — check UDJC code compiles and input fields exist", e); } Prevention
- Fix compile errors in UDJC code before clicking Test
- Always connect an upstream step providing the expected fields
- Keep the 'Fields' grid names in sync with upstream row structure
When it happens
Trigger: Clicking 'Test class' / preview in the UDJC dialog when the step's getFields() returns false — typically because the generated class failed to compile or the input fields could not be resolved.
Common situations: Java code with compile errors (bad imports, undefined variables); referencing input fields that do not exist in the previous step; no previous step connected so input row meta is empty.
Related errors
- Could not initialize from codeSnippets.xml
- Error executing UserDefinedJavaClass.getFields():
- Error initializing UserDefinedJavaClass to get fields:
- GetXMLDataDialog.Exception.FileDoesNotExist
- GetXMLDateLoopNodesImportProgressDialog.Exception.ErrorScann…
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/dd56b9b4dd0847e7.
Report an issue: GitHub.
Appendix: source
Thrown at ui/src/main/java/org/pentaho/di/ui/trans/steps/userdefinedjavaclass/UserDefinedJavaClassDialog.java:1429
etd.setReadOnly();
etd.open();
}
}
RowMetaInterface previewRowsMeta = progressDialog.getPreviewRowsMeta( wStepname.getText() );
List<Object[]> previewRows = progressDialog.getPreviewRows( wStepname.getText() );
if ( previewRowsMeta != null && previewRows != null && previewRows.size() > 0 ) {
PreviewRowsDialog prd =
new PreviewRowsDialog(
shell, transMeta, SWT.NONE, wStepname.getText(), previewRowsMeta, previewRows, loggingText );
prd.open();
}
}
return true;
} else {
throw new KettleException( BaseMessages.getString(
PKG, "UserDefinedJavaClassDialog.Exception.CouldNotGetFields" ) );
}
} catch ( Exception e ) {
new ErrorDialog(
shell, BaseMessages.getString( PKG, "UserDefinedJavaClassDialog.TestFailed.DialogTitle" ), BaseMessages
.getString( PKG, "UserDefinedJavaClassDialog.TestFailed.DialogMessage" ), e );
return false;
}
}
private void buildSnippitsTree() {
TreeItem item = new TreeItem( wTree, SWT.NULL );
item.setImage( guiResource.getImageBol() );
item.setText( BaseMessages.getString( PKG, "UserDefinedJavaClassDialog.Snippits.Label" ) );
Map<Category, TreeItem> categoryTreeItems = new EnumMap<Category, TreeItem>( Category.class );View on GitHub (pinned to f3058517a1)