pentaho/pentaho-kettle · error · RuntimeException
The function call year requires 1 argument.
Error message
The function call year requires 1 argument.
What it means
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().
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.
Example fix
// before var y = year(dateField.getString()); // after var y = year(dateField.getDate());
Defensive patterns
Strategy: validation
Validate before calling
var y = (d != null) ? year(d) : null;
Type guard
function isKettleDate(v) { return v != null && v instanceof java.util.Date; } Try / catch
try {
var y = year(d);
} catch (e) {
// message is either the arity error or e.toString() from the inner catch
Logger.LogBasic("year failed: " + e.message);
y = null;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Passing a string date instead of a Date field; passing a numeric field; forgetting that Kettle Date fields arrive as java.util.Date objects.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- The function call month requires 1 argument.
- The function call quarter requires 1 argument.
- The function call week requires 1 argument.
- The function call lpad requires 3 arguments.
- The function call rpad requires 3 arguments.
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/a0a5efce7761635a.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:841
}
return null;
}
public static Object year( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
Object FunctionContext ) {
try {
if ( ArgList.length == 1 ) {
if ( isNull( ArgList[0] ) ) {
return new Double( Double.NaN );
} else if ( isUndefined( ArgList[0] ) ) {
return undefinedValue;
}
java.util.Date dArg1 = (java.util.Date) ArgList[0];
Calendar cal = Calendar.getInstance();
cal.setTime( dArg1 );
return new Double( cal.get( Calendar.YEAR ) );
} else {
throw new RuntimeException( "The function call year requires 1 argument." );
}
} catch ( Exception e ) {
throw new RuntimeException( e.toString() );
}
}
public static Object month( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
Object FunctionContext ) {
try {
if ( ArgList.length == 1 ) {
if ( isNull( ArgList[0] ) ) {
return new Double( Double.NaN );
} else if ( isUndefined( ArgList[0] ) ) {
return undefinedValue;
}
java.util.Date dArg1 = (java.util.Date) ArgList[0];
Calendar cal = Calendar.getInstance();
cal.setTime( dArg1 );View on GitHub (pinned to f3058517a1)