{"record":{"id":"2956620ca1e0278c","repo":"pentaho/pentaho-kettle","slug":"unexpected-error-occurred-while-injecting-metadata","errorCode":null,"errorMessage":"Unexpected error occurred while injecting metadata","messagePattern":"Unexpected error occurred while injecting metadata","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/meta-inject/impl/src/main/java/org/pentaho/di/trans/steps/metainject/MetaInject.java","lineNumber":543,"sourceCode":"                try {\n                  List<StepInjectionMetaEntry> rowEntries = metaEntries.getDetails().get( i ).getDetails();\n\n                  for ( StepInjectionMetaEntry rowEntry : rowEntries ) {\n                    // We have to look up the sources for these targets again in the target-2-source mapping\n                    // That is because we only want handle this as few times as possible...\n                    //\n                    SourceStepField detailSource = findDetailSource( targetMap, targetStep, rowEntry.getKey() );\n                    if ( detailSource != null ) {\n                      setEntryValueIfFieldExists( rowEntry, row, detailSource );\n                    } else {\n                      if ( log.isDetailed() ) {\n                        logDetailed( \"No detail source found for key: \" + rowEntry.getKey() + \" and target step: \"\n                          + targetStep );\n                      }\n                    }\n                  }\n                } catch ( Exception e ) {\n                  throw new KettleException( \"Unexpected error occurred while injecting metadata\", e );\n                }\n              }\n\n              if ( log.isDetailed() ) {\n                logDetailed( \"injected entry: \" + entry );\n              }\n            }\n            // End of TopLevel/Detail if block\n          } else {\n            if ( log.isDetailed() ) {\n              logDetailed( \"entry not found: \" + target.getAttributeKey() );\n            }\n          }\n        } else {\n          if ( log.isDetailed() ) {\n            logDetailed( \"No rows found for source step: \" + source.getStepname() );\n          }\n        }","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/meta-inject/impl/src/main/java/org/pentaho/di/trans/steps/metainject/MetaInject.java#L525-L561","documentation":"Generic wrapper thrown by MetaInject.oldInjection() when any unexpected exception occurs while applying the injection mapping entries to the target steps of the child transformation. Per-entry metadata (source field/target field/target step) is set reflectively; a failure inside that loop — bad target step, incompatible field type, reflection error — is wrapped in this KettleException.","triggerScenarios":"During processRow -> oldInjection: an injection mapping references a target step or target field that doesn't exist in the child transformation, or setting a field on the step meta fails (type/ reflection/ NPE), caught by the catch(Exception) inside the entry loop.","commonSituations":"Child .ktr changed so mapped target fields no longer exist; injection source rows have wrong types for the target field; mapping CSV/Excel defined against an older transformation version; null source values injected into primitives.","solutions":["Read the wrapped cause (e) in the log — it names the actual failing target step/field","Open the Meta Inject mapping grid and remove/fix entries whose target step or target field no longer exists in the child transformation","Re-generate the mapping from the source and target transformations so field names and types are current","Validate source field types against the target step meta (e.g. string vs integer) and add Select Values conversions if needed"],"exampleFix":"// before: mapping to a field removed from the child step\nentry.setTargetField('oldFieldName');\n// after\nentry.setTargetField('currentFieldName'); // per current child .ktr step meta","handlingStrategy":"try-catch","validationCode":"// Validate mapping targets against the child transformation before injection\nfor (MetaInjectTransformationTargetTarget t : targets) {\n  StepMeta step = child.findStep(t.getTargetStep());\n  if (step == null) throw new IllegalStateException('Unknown target step: ' + t.getTargetStep());\n  // verify field exists in step meta via step.getStepMetaInterface() reflection if needed\n}","typeGuard":"boolean mappingTargetsValid(TransMeta child, java.util.Map<String,String> targetSteps) {\n  return targetSteps.values().stream().allMatch(n -> child.findStep(n) != null);\n}","tryCatchPattern":"try {\n  // execute meta injection\n} catch (KettleException e) {\n  if (e.getMessage().contains('Unexpected error occurred while injecting metadata')) {\n    log.error('Injection mapping mismatch; cause: ' + e.getCause(), e);\n    // regenerate mapping and retry once\n  } else throw e;\n}","preventionTips":["Regenerate the mapping grid after any child .ktr change","Check source/target field types before injection (add Select Values conversions)","Avoid null values in injection source rows","Store the mapping definition alongside the child .ktr in version control"],"tags":["metadata-injection","reflection","mapping"],"backgroundTag":"internal-invariant-violation","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"}