pentaho/pentaho-kettle · error · KettleException
Unable to look up Null if value for field
Error message
Unable to look up Null if value for field
What it means
getFieldNullIf resolves a field name to its 'null if' replacement string in the Data Grid. When the requested fieldName does not exist among the grid's field names, it throws this KettleException naming the field.
Solutions
- Verify the field name exists in the Data Grid (exact spelling and case) and correct the caller's argument.
- Use getFieldNullIf(String) only after loading the step metadata (loadXML/readRep) so field arrays are populated.
- Enumerate getFieldName() first and pick the exact entry instead of guessing the name.
- If programmatic, match case-insensitively against the field list before calling.
Example fix
// before
String nv = meta.getFieldNullIf("qty"); // not in grid
// after
if (Arrays.asList(meta.getFieldName()).contains("qty")) {
String nv = meta.getFieldNullIf("qty");
} Defensive patterns
Strategy: type-guard
Validate before calling
boolean exists = Arrays.asList(meta.getFieldName()).contains(fieldName);
if (!exists) throw new IllegalArgumentException("Field not in DataGrid: " + fieldName); Type guard
int fieldIndex(DataGridMeta m, String name){
String[] names = m.getFieldName();
for (int i=0;i<names.length;i++) if (names[i].equals(name)) return i;
return -1;
} Try / catch
try { String nv = meta.getFieldNullIf(fieldName); }
catch (KettleException e) {
logError("Field not found in DataGrid: " + fieldName, e);
nv = null; // or fail fast depending on use
} Prevention
- Look up fields with exact spelling/case as defined in the grid.
- Call only after loadXML/readRep has populated the metadata.
- Enumerate getFieldName() instead of guessing names.
- Re-check lookups after any grid edit or rename.
When it happens
Trigger: Calling getFieldNullIf(fieldName) with a name that is not in this.getFieldName(); note the loop also scans off-by-one (index-1 after the found position), so callers passing a name that matches only partially or with different case also fail.
Common situations: Plugin/script code looking up a field that was renamed or deleted from the grid; case-sensitive name mismatch ('Qty' vs 'qty'); lookup before the step metadata finished loading.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- ColumnExists.Exception.CouldnotFindField
- CombinationLookup.Exception.FieldNotFound
- Couldn't find field ' ' in row!
- CsvInput.Exception.FilenameFieldNotFound (with…
- ExecSQLRow.Exception.CouldnotFindField
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/a59b8921960d275d.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/datagrid/DataGridMeta.java:395
}
} catch ( Exception e ) {
throw new KettleStepException( "Unable to create value of type " + fieldType[i], e );
}
}
}
public String getFieldNullIf( String fieldName ) throws KettleException {
int index;
boolean found = false;
String nullIfVal = null;
if ( null != fieldName ) {
for ( index = 0; index < this.getFieldName().length && !found; index++ ) {
found = fieldName.compareTo( this.getFieldName()[index] ) == 0;
}
if ( found ) {
nullIfVal = this.getFieldNullIf()[index - 1];
} else {
throw new KettleException( "Unable to look up Null if value for field " + fieldName );
}
}
return nullIfVal;
}
@Override
public String getXML() {
StringBuilder retval = new StringBuilder( 300 );
retval.append( " <fields>" ).append( Const.CR );
for ( int i = 0; i < fieldName.length; i++ ) {
if ( fieldName[i] != null && fieldName[i].length() != 0 ) {
retval.append( " <field>" ).append( Const.CR );
retval.append( SPACES_XML ).append( XMLHandler.addTagValue( "name", fieldName[i] ) );
retval.append( SPACES_XML ).append( XMLHandler.addTagValue( "type", fieldType[i] ) );
retval.append( SPACES_XML ).append( XMLHandler.addTagValue( "format", fieldFormat[i] ) );
retval.append( SPACES_XML ).append( XMLHandler.addTagValue( "currency", currency[i] ) );
retval.append( SPACES_XML ).append( XMLHandler.addTagValue( "decimal", decimal[i] ) );View on GitHub (pinned to f3058517a1)