{"record":{"id":"a0a5efce7761635a","repo":"pentaho/pentaho-kettle","slug":"the-function-call-year-requires-1-argument","errorCode":null,"errorMessage":"The function call year requires 1 argument.","messagePattern":"The function call year requires 1 argument\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":841,"sourceCode":"    }\n    return null;\n  }\n\n  public static Object year( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 ) {\n        if ( isNull( ArgList[0] ) ) {\n          return new Double( Double.NaN );\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return undefinedValue;\n        }\n        java.util.Date dArg1 = (java.util.Date) ArgList[0];\n        Calendar cal = Calendar.getInstance();\n        cal.setTime( dArg1 );\n        return new Double( cal.get( Calendar.YEAR ) );\n      } else {\n        throw new RuntimeException( \"The function call year requires 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n  }\n\n  public static Object month( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 ) {\n        if ( isNull( ArgList[0] ) ) {\n          return new Double( Double.NaN );\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return undefinedValue;\n        }\n        java.util.Date dArg1 = (java.util.Date) ArgList[0];\n        Calendar cal = Calendar.getInstance();\n        cal.setTime( dArg1 );","sourceCodeStart":823,"sourceCodeEnd":859,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L823-L859","documentation":"year(date) returns the year of a java.util.Date as a Double via Calendar.get(Calendar.YEAR). It requires exactly one argument; with any other count it throws this RuntimeException, and any other exception inside the try is rethrown by the outer catch as e.toString().","triggerScenarios":"Calling year() with zero arguments or two-plus arguments in a Script step; passing a non-Date first argument (ClassCastException when cast to java.util.Date); passing null.","commonSituations":"Passing a string date instead of a Date field; passing a numeric field; forgetting that Kettle Date fields arrive as java.util.Date objects.","solutions":["Call year() with exactly one Date-typed argument.","Convert string dates first, e.g. year(str2date(dateString, \"yyyy-MM-dd\")).","Guard against null dates before calling year().","Read e.toString() in the log to distinguish argument-count vs cast failures."],"exampleFix":"// before\nvar y = year(dateField.getString());\n// after\nvar y = year(dateField.getDate());","handlingStrategy":"validation","validationCode":"var y = (d != null) ? year(d) : null;","typeGuard":"function isKettleDate(v) { return v != null && v instanceof java.util.Date; }","tryCatchPattern":"try {\n  var y = year(d);\n} catch (e) {\n  // message is either the arity error or e.toString() from the inner catch\n  Logger.LogBasic(\"year failed: \" + e.message);\n  y = null;\n}","preventionTips":["Pass exactly one java.util.Date to year().","Convert strings with str2date() first.","Null-check before calling.","Note Calendar.MONTH-based siblings behave the same way."],"tags":["javascript","script-step","argument-count","date","pentaho-kettle"],"backgroundTag":"missing-required-argument","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"}