Status/Resolution/Reason: Closed/Fixed/
Reporter/Name(from Bugbase): Peter Boughton / Peter Boughton (Peter Boughton)
Created: 10/17/2014
Components: Language
Versions: 11.0
Failure Type:
Found In Build/Fixed In Build: CF11_Final / CF11 Update5
Priority/Frequency: Major / All users will encounter
Locale/System: ALL / Windows 7 64-bit
Vote Count: 2
The null coalescing operator ( a ?: b ) does not always correctly identify when the first operand should be used.
Not knowing when it's going to work and when it is not makes the functionality completely useless.
Consider this code:
__debug('Object: #prc.Object.getId()#');
__debug('test: # prc.Object.getId() ?: "?: is broken" #');
The __debug function here is simply a wrapper for writeLog.
prc.Object is populated with a Hibernate entity; the id is not null.
The output in the log file is:
Object: 4
test: ?: is broken
Since "4" is not null, the second line is behaving incorrectly - it should also be outputting 4
This is repeatable on every request.
Another example, using writeLog directly:
if ( NOT StructKeyExists(Server.SomeStruct,Key) )
Server.SomeStruct[Key] = getData( Params );
...
writeLog(text="Found: #(Server.SomeStruct[Key] ?: '<EMPTY>')#",file="LogFile");
In this case, getData will return null or a struct with a single column - yet when the struct is returned the result is still incorrectly '<EMPTY>'
<cffunction name="getData" returntype="any" output=false access="private">
<!--- query --->
<cfif SimpleQuery.RecordCount and len(SimpleQuery.ColumnName)>
<cfreturn { ColumnName : SimpleQuery.ColumnName } />
</cfif>
</cffunction>
The operator does sometimes work - the following code is correctly picking up var1 and var3 (not tested for var2) but uses empty string when none are defined:
var ApiToken = url.var1 ?: getHttpRequestData().headers.var2 ?: url.var3 ?: '';
However, as before, without any rationale for when it will work or fail the functionality is unusable until fixed.
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3840570
External Customer Info:
External Company:
External Customer Name: boughtonp
External Customer Email:
External Test Config: My Hardware and Environment details:
Attachments:
Comments: