tracker issue : CF-3840570

select a category, or use search below
(searches all categories and all time range)
Title:

null coalescing operator sometimes incorrectly returns the second operand

| View in Tracker

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

Listed in the version 11.0.05.293506 Issues Fixed doc
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:

The fix for this bug is available in the pre-release build of ColdFusion 11 Update 5
Comment by CFwatson U.
10601 | February 20, 2015 09:26:48 AM GMT
What kind of clown show is this? I guess I should just go back to being a 5-tagger, where it's safe.
Vote by External U.
10608 | February 26, 2015 09:22:19 AM GMT
This is ridiculous. On the one CF project I have left, almost every hour I've spent over the past few months has been spent on getting things working reliably under CF11.
Vote by External U.
10609 | February 26, 2015 08:29:17 PM GMT
We see some votes here, are these code snippets not working with Update 5 (PR)?
Comment by Vamseekrishna N.
10602 | March 11, 2015 01:23:13 AM GMT
Yes, it *still* fails in the second pre-release of update 5 - i.e. this issue should never have been closed. These two expressions should always output the same thing (either both outputting the value of a[b] or both outputting the string 'n/a'), but the null coalescing operator is outputting n/a even when it shouldn't. #a[b]?:'n/a'# #StructKeyExists(a,b)?a[b]:'n/a'#
Comment by External U.
10603 | March 12, 2015 02:56:19 PM GMT
Hi Peter, We acknowledge that this is an issue . Thanks for reporting it. We have logged another bug to track this. For your reference,this is the bug no: CF-3952818. Thanks, Suchika
Comment by Suchika S.
10604 | March 13, 2015 07:03:53 AM GMT
Thanks Suchika. I tried viewing bug CF-3952818 but I get the message "The information requested is not found" Is that the correct number?
Comment by External U.
10605 | March 13, 2015 07:27:09 AM GMT
Hi Peter, The bug was not made external. Just made it. You can view that now. Thanks, Suchika
Comment by Suchika S.
10606 | March 13, 2015 07:47:23 AM GMT
Hi Suchika, What exactly was fixed in this ticket? Could a standalone repro case be attached? I see CF-3952818 was created for an issue that looks like it was part of this ticket. Thanks!, -Aaron
Comment by External U.
10607 | November 21, 2015 06:28:11 AM GMT