Is dateAdd enforcement of params more strict in 5.4?

We have some older (embarrassing copy/paste or transposed param errors) running smoothly in 5.3.x (and prior) … and found some possibly-breaking-changes (fixes?) in 5.4

  • Most of these are within 3 years, once instance was 7 years ago so likely was ACF.

Is this intentional to enforce the correct parameter sequence?

  • If so, shouldn’t “case 1” also be failing?
<!--- Case 1: Add string (pass) --->
<cftry>
	<cfset myDate1_plus_90 = dateAdd("d", "2023-07-05", 90) />
	<cfdump var="#myDate1_plus_90#" label="case 1 pass" />

	<cfcatch>
		<cfdump var="#cfcatch#" label="case 1 fail" />
	</cfcatch>
</cftry>

<!--- Case 2: Add YYYY-MM-DD date string (fail) --->
<cftry>
	<cfset myDate2 = "2023-07-05" />
	<cfset myDate2_plus_90 = dateAdd("d", myDate2, 90) />
	<cfdump var="#myDate2_plus_90#" label="case 2 pass" />

	<cfcatch>
		<cfdump var="#cfcatch#" label="case 2 fail" />
	</cfcatch>
</cftry>

<!--- Case 3: Add Formatted date string (fail) --->
<cftry>
	<cfset myDate3 = dateFormat(now(), "yyyy-mm-dd") />
	<cfset myDate3_plus_90 = dateAdd("d", myDate3, 90) />
	<cfdump var="#myDate3_plus_90#" label="case 3 pass" />

	<cfcatch>
		<cfdump var="#cfcatch#" label="case 3 fail" />
	</cfcatch>
</cftry>

Top of the stack trace:

lucee.runtime.exp.CasterException: cannot cast [2023-07-05] string to a number value at lucee.runtime.op.Caster.toDoubleValue(Caster.java:479) at lucee.runtime.op.Caster.toDoubleValue(Caster.java:402) at index_cfm$cf$p.call(/index.cfm:14) 

Don’t forget to tell us about your stack!
Environment:
OS: Windows 64-bit
Java Version: 11.0.7 (AdoptOpenJDK) 64bit
Tomcat Version: Tomcat/9.0.64
Lucee Version: Lucee 5.4.1.4-SNAPSHOT

Edit: Added pass/fail/fail to respective test case comments in code. I would expect all to pass or all to fail.

First case raises an error in Lucee 6.0.0-SNAPSHOT+451 (beta) too.

java.lang.NoSuchMethodError
lucee.runtime.op.Caster.toDoubleValue(Llucee/runtime/PageContext;Ljava/lang/String;)D
1 Like

confirmed regression [LDEV-4616] - Lucee

3 Likes

the argument order is wrong btw

DateAdd( datePart=string, number=number, date=datetime );

Yep … thank you.
2nd and 3rd params swapped is certainly worth pointing out again though so others don’t copy my errors.

I’d even support drawing a line and saying “Won’t fix”. I have a code cleanup ticket (for my bad code) and am okay either way.