{"record":{"id":"1a9852fa996bc9fa","repo":"pentaho/pentaho-kettle","slug":"the-result-of-the-filter-expression-must-be-a-boolean-and-we","errorCode":null,"errorMessage":"The result of the filter expression must be a boolean and we got back : {className}","messagePattern":"The result of the filter expression must be a boolean and we got back : (.+?)","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/javafilter/JavaFilter.java","lineNumber":205,"sourceCode":"        // Also create the argument data structure once...\n        //\n        data.argumentData = new Object[data.argumentIndexes.size()];\n      }\n\n      // This method can only accept the specified number of values...\n      //\n      for ( int x = 0; x < data.argumentIndexes.size(); x++ ) {\n        int index = data.argumentIndexes.get( x );\n        ValueMetaInterface outputValueMeta = data.outputRowMeta.getValueMeta( index );\n        data.argumentData[x] = outputValueMeta.convertToNormalStorageType( r[index] );\n      }\n\n      Object formulaResult = data.expressionEvaluator.evaluate( data.argumentData );\n\n      if ( formulaResult instanceof Boolean ) {\n        return (Boolean) formulaResult;\n      } else {\n        throw new KettleException( \"The result of the filter expression must be a boolean and we got back : \"\n          + formulaResult.getClass().getName() );\n      }\n    } catch ( Exception e ) {\n      throw new KettleValueException( e );\n    }\n  }\n\n  public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {\n    meta = (JavaFilterMeta) smi;\n    data = (JavaFilterData) sdi;\n\n    if ( super.init( smi, sdi ) ) {\n      List<StreamInterface> targetStreams = meta.getStepIOMeta().getTargetStreams();\n      data.trueStepname = targetStreams.get( 0 ).getStepname();\n      data.falseStepname = targetStreams.get( 1 ).getStepname();\n\n      if ( targetStreams.get( 0 ).getStepMeta() != null ^ targetStreams.get( 1 ).getStepMeta() != null ) {\n        logError( BaseMessages.getString( PKG, \"JavaFilter.Log.BothTrueAndFalseNeeded\" ) );","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/javafilter/JavaFilter.java#L187-L223","documentation":"Thrown by the Java Filter step's keep() method when the compiled filter expression evaluates to a non-Boolean value. The filter contract requires the Java expression to return a boolean so rows can be routed to the true/false branches.","triggerScenarios":"data.expressionEvaluator.evaluate(argumentData) returns an object whose class is not Boolean — e.g. the expression ends with an assignment, a comparison wrapped by a method returning Object, or an expression like (a > b) ? 1 : 0 typed as int.","commonSituations":"Writing an expression whose result is int/String instead of boolean (e.g. using bitwise & instead of &&, or returning a numeric flag); a typo causing the evaluator's generic Object return path; copy-pasting a formula expression from the Formula step into Java Filter.","solutions":["Rewrite the filter expression so it evaluates to boolean (use comparisons and logical operators: ==, >, &&, ||).","Do not use numeric 0/1 flags; use (value == 0) instead.","Check for accidental casts or method calls returning Object; coerce explicitly, e.g. Boolean.parseBoolean(str).","Read the className in the message — it names the actual returned type to fix."],"exampleFix":"// before\nexpression: amount & 1\n// after\nexpression: (amount & 1) == 1","handlingStrategy":"type-guard","validationCode":"// Sanity-check the expression ends in a boolean comparison\nString expr = meta.getCondition();\nif (!expr.matches(\".*(==|!=|>|<|>=|<=|&&|\\|\\|).*\")) {\n  throw new IllegalStateException(\"Filter expression must compare/return boolean: \" + expr);\n}","typeGuard":"boolean isBooleanResult(Object result) { return result instanceof Boolean; }","tryCatchPattern":"try { boolean keep = calcFields(row); } catch (KettleValueException e) { logError(\"Filter expression error: \" + e.getMessage()); throw e; }","preventionTips":["Only write boolean expressions in Java Filter (comparisons joined with && / ||).","Never return numeric flags; convert them: (flag == 1).","Test the filter with sample data before scheduling."],"tags":["kettle","filter","type-mismatch"],"backgroundTag":"type-mismatch","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"}