{"record":{"id":"5e9c02f2a40424d7","repo":"pentaho/pentaho-kettle","slug":"unknown-value-v-for-enum-enumclass","errorCode":null,"errorMessage":"Unknown value ${v} for enum ${enumClass}","messagePattern":"Unknown value (.+?) for enum (.+?)","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/injection/DefaultInjectionTypeConverter.java","lineNumber":71,"sourceCode":"  }\n\n  @Override\n  public Boolean string2boolean( String v ) {\n    return v == null ? null : string2booleanPrimitive( v );\n  }\n\n  @Override\n  public Enum<?> string2enum( Class<?> enumClass, String v ) throws KettleValueException {\n    if ( v == null ) {\n      return null;\n    }\n    for ( Object eo : enumClass.getEnumConstants() ) {\n      Enum<?> e = (Enum<?>) eo;\n      if ( e.name().equals( v ) ) {\n        return e;\n      }\n    }\n    throw new KettleValueException( \"Unknown value \" + v + \" for enum \" + enumClass );\n  }\n\n  @Override\n  public String boolean2string( Boolean v ) throws KettleValueException {\n    if ( v == null ) {\n      return null;\n    }\n    return v ? \"Y\" : \"N\";\n  }\n\n  @Override\n  public int boolean2intPrimitive( Boolean v ) throws KettleValueException {\n    return v ? 1 : 0;\n  }\n\n  @Override\n  public Integer boolean2integer( Boolean v ) throws KettleValueException {\n    return v == null ? null : boolean2intPrimitive( v );","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/injection/DefaultInjectionTypeConverter.java#L53-L89","documentation":"DefaultInjectionTypeConverter.string2enum converts a string to an enum constant by exact name match across enumClass.getEnumConstants(). When no constant's name() equals the input, Kettle throws KettleValueException. This guards metadata-injection value parsing from silently producing null enums.","triggerScenarios":"Calling string2enum(v, enumClass) (directly or via metadata injection of a field whose converter is the enum converter) with a string that is not an exact enum constant name, including wrong case or trailing whitespace.","commonSituations":"Importing a transformation exported from a different Pentaho/Kettle version where the enum gained/lost constants; hand-edited XML or injection spreadsheets with misspelled or case-mismatched enum values.","solutions":["Fix the injected value to exactly match an enum constant name (case-sensitive, no whitespace).","Check the target enum class (printed in the message) for the valid constant names in your Kettle version.","If values come from an older version, map legacy names to current enum constants before injection.","If you control the converter pipeline, normalize the string (trim, upper/lower) before conversion."],"exampleFix":"// before\nconverter.string2enum(\"Batchl\", updateMode.getClass());\n// after\nconverter.string2enum(\"Batch\", updateMode.getClass()); // exact enum name","handlingStrategy":"validation","validationCode":"boolean valid = java.util.Arrays.stream(MyEnum.values()).anyMatch(e -> e.name().equals(candidateValue));\nif (!valid) throw new IllegalArgumentException(\"Value not a valid \" + MyEnum.class.getSimpleName() + \": \" + candidateValue);","typeGuard":"static <E extends Enum<E>> boolean isValidEnumValue(Class<E> type, String v) {\n  if (v == null) return false;\n  return Arrays.stream(type.getEnumConstants()).anyMatch(e -> e.name().equals(v));\n}","tryCatchPattern":"try {\n  Enum<?> mode = converter.string2enum(value, MyEnum.class);\n} catch (KettleValueException e) {\n  log.logError(\"Invalid enum value for injection: \" + e.getMessage());\n  mode = defaultValue;\n}","preventionTips":["Validate injected strings against Enum.values() names before conversion.","Trim and normalize case of source values before injection.","Keep enum values consistent between exported metadata and target Kettle version.","Document accepted values next to the injection field definition."],"tags":["kettle","enum","metadata-injection","type-conversion"],"backgroundTag":"invalid-enum-value","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"}