A highly unusual ColdFusion arguments error

This post is more than 2 years old.

This one is weird. I don't mean kinda weird. I mean bat-crap insane what-the-hell type weird. Earlier today Jeremy Tan sent me some code that acted a bit odd. Let's take a look at it.

In the code snippet above, you can see some data being passed to a CFC within a transaction. Note - there are no actual database calls here, but that doesn't matter. The CFC is simply doing a dump of the Arguments scope:

Now let's look at the output. There should be 6 dumps from the set() call and one in the middle for test2.

Um... ok. We have 8 dumps. We don't have the dump of test2. Also note the third dump, which should have "Bob in line 2", has it as 9. Oh, and even better, i is 2, not 3.

Things get weirder if we simplify. I commented out everything but the last two calls:

Yep, three dumps. Here is where things get even more weird. Jeremy found that if he simply stopped using named arguments and switched to ordered ones, everything worked fine.

If there was a bug with the data being displayed (oh wait, there is that too), then I'd maybe think it made sense. Again, as a bug. But the additional calls just don't make sense at all.

Obviously this is could be really bad for anyone doing CFC calls inside a transaction. You can find Jeremy's forum post on the topic here: Weird transaction issue with implicit struct (and possible array). I've also asked him to fill out a bug report and post the link here.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Dave Oram posted on 2/27/2013 at 6:42 AM

Well done Jeremy. Wish I had know this a few days ago.

Comment 2 by Raymond Camden posted on 2/27/2013 at 6:46 AM

Did you actually run into this too?

Comment 3 by David Mitchell posted on 2/27/2013 at 6:46 AM

found the bug: https://bugbase.adobe.com/i...

i have been struggling with this for a while now. Good to know that I am not the only one.

Comment 4 by david oram posted on 2/27/2013 at 6:47 AM

Yeah - seen it recently - wierd eh!

Comment 5 by Raymond Camden posted on 2/27/2013 at 6:49 AM

Wow, ok. Well, glad he found it and I'm glad I'm helping spread the word then. ;)

David - thanks for posting the bug link.

Comment 6 by Raymond Camden posted on 2/27/2013 at 6:50 AM

I added a note to the bug saying it happens in 10 as well.

Comment 7 by Adam Cameron posted on 3/1/2013 at 12:33 AM

The repro case can be pared back much further than this:

<!--- repro.cfm --->
<cfscript>
o = new C();
transaction {
a=1; // any statement at all
o.f(arg1={key1="value 1"}); // only a problem with named args & struct-literal notation
}
</cfscript>

// C.cfc
component {

function f(){
writeDump(arguments);
}

}

Comment 8 by Adam Cameron posted on 3/1/2013 at 12:34 AM

Blimey. And it's not just a transaction{} thing, it seems it's ANY block-level construct. This also does it:

<cfscript>
o = new C();
try {
a=1; // any statement at all
o.f(arg1={key1="value 2"}); // only a problem with named args & struct-literal notation
}
catch (any e){

}
</cfscript>

Comment 9 by Raymond Camden posted on 3/1/2013 at 12:37 AM

Damn. Adam, please be sure to add a note to the bug report. This is pretty darn big. Does if{} also have the bug?

Comment 10 by Adam Cameron posted on 3/1/2013 at 12:38 AM

Indeed it doesn't even need the CFC:
<cfscript>
try {
a=1; // any statement at all
f(arg1={key1="value 3"}); // only a problem with named args & struct-literal notation
}
catch (any e){

}

function f(){
writeDump(arguments);
}
</cfscript>

Comment 11 by Adam Cameron posted on 3/1/2013 at 12:39 AM

Yes, it's with if() too. Bloody hell.

<cfscript>
if(true) {
a=1; // any statement at all
f(arg1={key1="value 3"}); // only a problem with named args & struct-literal notation
}

function f(){
writeDump(arguments);
}
</cfscript>

Comment 12 by larry c. lyons posted on 3/1/2013 at 2:03 AM

A question, does this just happen with script based code or with the more traditional tag based stuff?

Comment 13 by Raymond Camden posted on 3/1/2013 at 2:05 AM

What did you see when you tried it Larry? ;)

Comment 14 by larry c. lyons posted on 3/1/2013 at 2:17 AM

I'll have to try it this evening. These people here actually expect me to work. The nerve!

Comment 15 by Raymond Camden posted on 3/1/2013 at 2:18 AM

Heh, bastards! ;)

Comment 16 by Louis posted on 3/1/2013 at 2:37 PM

Wow! This is fascinating. Has anyone checked CF<10 or Railo?

Comment 17 by Louis posted on 3/1/2013 at 2:42 PM

@ larry - Tags don't seem to be affected:

<p>CFScript</p>

<cfscript>
try {
a = 1;
f(arg1={key1="value 3"});
}
catch (any e){}

function f(){
writeDump(arg1);
}
</cfscript>

<p>Tag Based</p>

<cftry>
<cfset a = 1>
<cfset f2(arg1={key1="value 3"})>
<cfcatch type="any">
</cfcatch>
</cftry>

<cffunction name="f2">
<cfdump var="#arg1#">
</cffunction>

Comment 18 by Bill Davidson posted on 3/8/2013 at 9:17 AM

Yeah - Larry. Back to work. Why would you be using tags anyways? :)

Seriously - this a pretty big issue. I wonder if I have hit this before and just thought it was me!