CFSwitch change after p740 / Lucee 5.3 upgrade

Just wondering if I’m missing something obvious.

Following property on a custom type:

<cfproperty
    name="timetableDisplayOption" type="numeric" required="false" default="1"
    ftSeq="40" ftFieldSet="Timetable" ftWizardStep="Timetable"
    ftLabel="Timetable Display" ftType="list" ftList="0:None,1:Use richtext,2:Use items" >

Usage code (dumps and default for debugging only :slight_smile: )

<cfdump var="#stObj.timetableDisplayOption#" >
<cfdump var="#stObj.timetableDisplayOption eq 2#" >
<cfdump var="#stObj.timetableDisplayOption eq 2.0#" >
<cfdump var="#stObj.timetableDisplayOption eq "2"#" >
<cfdump var="#stObj.timetableDisplayOption eq "2.0"#" >
<cfswitch expression="#stObj.timetableDisplayOption#" >
    <cfcase value="1" >
        #stObj.timetableHTML#
    </cfcase>
    <cfcase value="2" >
        <skin:view stObject="#stObj#" webskin="#stObj.timetableWebskin#" />
    </cfcase>
    <cfdefaultcase>
        WHY?!?
    </cfdefaultcase>
</cfswitch>

Worked as expected on FarCry 7.2.12, Lucee 5.2.9, Java 8.

On FarCry p740, Lucee 5.3.10, Java 11 we get:

image

Any ideas?

After further investigation, I think the cause has been found as part of the Lucee upgrade, specifically this commit: https://github.com/lucee/Lucee/commit/ec467ba609bf8d61f3afb3068a04e94fe17be92e

This is a guess, but what seems to be happening is that:

  1. The number has to be a java.math.BigDecimal, in this case due to being sourced from the database
  2. When it gets to the cfswitch the BigDecimal gets converted to a string
  3. The string is then compared to the cfcase values

This worked previously because the BigDecimal would first get converted to a Double, then checked against a long, and because Double(2.00) == Long(2), the string produced is the string version of the long value, resulting in β€œ2” being the cfswitch comparison.

Due to the change, the BigDecimal now skips the comparison and the string equivilant is β€œ2.00” which is not equal to the string β€œ2”.

Some work arounds to this are:

  1. expression = "#int(stObj.timetableDisplayOption)#"
  2. expression = "#stObj.timetableDisplayOption / 1#"
  3. expression = "#numberFormat(stObj.timetableDisplayOption, "0")#"

Off to the Lucee forums :slight_smile:

1 Like

That must have taken some serious debugging to track down. It is possible to add a precision to the property, e.g. with dbPrecision=8,0, but it’s hard to say if that would translate to a different type in Lucee.

1 Like