{"record":{"id":"dd56b9b4dd0847e7","repo":"pentaho/pentaho-kettle","slug":"userdefinedjavaclassdialog-exception-couldnotgetfields","errorCode":null,"errorMessage":"UserDefinedJavaClassDialog.Exception.CouldNotGetFields","messagePattern":"UserDefinedJavaClassDialog\\.Exception\\.CouldNotGetFields","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"ui/src/main/java/org/pentaho/di/ui/trans/steps/userdefinedjavaclass/UserDefinedJavaClassDialog.java","lineNumber":1429,"sourceCode":"              etd.setReadOnly();\n              etd.open();\n            }\n          }\n\n          RowMetaInterface previewRowsMeta = progressDialog.getPreviewRowsMeta( wStepname.getText() );\n          List<Object[]> previewRows = progressDialog.getPreviewRows( wStepname.getText() );\n\n          if ( previewRowsMeta != null && previewRows != null && previewRows.size() > 0 ) {\n            PreviewRowsDialog prd =\n              new PreviewRowsDialog(\n                shell, transMeta, SWT.NONE, wStepname.getText(), previewRowsMeta, previewRows, loggingText );\n            prd.open();\n          }\n        }\n\n        return true;\n      } else {\n        throw new KettleException( BaseMessages.getString(\n          PKG, \"UserDefinedJavaClassDialog.Exception.CouldNotGetFields\" ) );\n      }\n    } catch ( Exception e ) {\n      new ErrorDialog(\n        shell, BaseMessages.getString( PKG, \"UserDefinedJavaClassDialog.TestFailed.DialogTitle\" ), BaseMessages\n          .getString( PKG, \"UserDefinedJavaClassDialog.TestFailed.DialogMessage\" ), e );\n      return false;\n    }\n\n  }\n\n  private void buildSnippitsTree() {\n\n    TreeItem item = new TreeItem( wTree, SWT.NULL );\n    item.setImage( guiResource.getImageBol() );\n    item.setText( BaseMessages.getString( PKG, \"UserDefinedJavaClassDialog.Snippits.Label\" ) );\n\n    Map<Category, TreeItem> categoryTreeItems = new EnumMap<Category, TreeItem>( Category.class );","sourceCodeStart":1411,"sourceCodeEnd":1447,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/ui/src/main/java/org/pentaho/di/ui/trans/steps/userdefinedjavaclass/UserDefinedJavaClassDialog.java#L1411-L1447","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nObject[] r = new Object[data.outputRowMeta.size()]; // uses wrong meta\n// after\nObject[] r = RowDataUtil.allocateRowData(data.outputRowMeta.size());","handlingStrategy":"try-catch","validationCode":"// before testing the class, confirm input meta resolves\nif (transMeta.getPrevStepFields(stepMeta) == null || transMeta.getPrevStepFields(stepMeta).isEmpty()) {\n  throw new KettleException(\"UDJC step has no input fields; connect a previous step first\");\n}","typeGuard":"boolean canGetFields(TransMeta tm, StepMeta sm) { try { return tm.getStepFields(sm) != null; } catch (Exception e) { return false; } }","tryCatchPattern":"try { testClass(); } catch (KettleException e) { new ErrorDialog(shell, \"Test failed\", \"Could not get fields — check UDJC code compiles and input fields exist\", e); }","preventionTips":["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"],"tags":["kettle","udjc","getfields","compile-error","dialog"],"backgroundTag":"unexpected-response-shape","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"}