Learning ColdFusion 9: Bug Using Implicit Structs Within Nested Function Calls

Posted July 30, 2009 at 1:40 PM by Ben Nadel

Tags: ColdFusion

Last night, when I was playing around with ColdFusion 9's new Object-Relational Mapping (ORM) functionality, I think I found a compile-time bug. I say compile-time because the following code throws an error even if I put a CFAbort at the top:

  • <!--- Load the girl object based on the name. --->
  • <cfset joanna = entityLoad(
  • "Girl",
  • { name = "Joanna" },
  • true
  • ) />
  •  
  • <!---
  • Override Joanna's properties with a new collection.
  • Because we don't know the IDs of the given properties,
  • we need to search for them by name.
  •  
  • NOTE: Use the "TRUE" uniqueness parameter to make sure that
  • these entityLoad() methods return a CFC, not an array.
  • --->
  • <cfset joanna.setProperties(
  • [
  • entityLoad(
  • "Property",
  • { name = "Athletic" },
  • true
  • ),
  • entityLoad(
  • "Property",
  • { name = "Brunette" },
  • true
  • )
  • ]
  • ) />

As you can see, all I'm doing here is loading a Girl.cfc instance and then overriding its collection of Property.cfcs. This throws the following ColdFusion error:

Unable to complete CFML to Java translation. Error information unknown node type coldfusion.compiler.ASTStructInitializer@189eab7

I narrowed down the problem to the fact that I was calling EntityLoad() as part of an implicit array that was being passed to a function call. When I moved the EntityLoad() calls outside of the SetProperties() call, everything worked fine.

At first, I thought maybe this was a bug with EntityLoad() or some other ORM feature; but, because this appears to be a compile-time issue, I wanted to see if I could duplicate the error with a much smaller bit of code:

  • <!--- Test method returns a struct. --->
  • <cffunction name="test">
  • <cfreturn arguments[ 1 ] />
  • </cffunction>
  •  
  • <!---
  • Get an array containing our nested struct that is returned
  • from the method.
  • --->
  • <cfset data = test(
  • [
  • test(
  • { foo = "Bar" }
  • )
  • ]
  • ) />

This simple demo also throws the ColdFusion error:

Unable to complete CFML to Java translation. Error information unknown node type coldfusion.compiler.ASTStructInitializer@1b5027d

I tried a whole bunch of different combinations of nested structs and arrays - it didn't matter. As long as the outer expression was a method call and as long as there were at least two levels of implicit object creation (struct or array) in which the inner-most one was wrapped inside of another method call, the error was thrown.

ColdFusion 9 definitely made some good steps forward with allowing us to pass implicit structs and arrays to method calls; but, it looks like they still need to iron some of the complex nesting that this sort of syntax invites.


You Might Also Be Interested In:



Reader Comments

Jul 30, 2009 at 1:49 PM // reply »
11,246 Comments

I have filed a bug for this:

http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=79175

After searching the Bug database, looks like CFLoop was having a similar bug, which has since been closed. Hopefully, this has already been fixed.


Jan 29, 2011 at 4:22 PM // reply »
1 Comments

Hi Ben

Is this another bug? I have broken it down to it's simplest form.

var local.result = {};

// add the page details to result
local.result['page'] = 1;
local.result['records'] = 2;
local.result['total'] = 3;

local.result['rows'] = [];

cfdrop( local.result );

This all works as expected but add an if statement (which can be anything) and the array just vanishes. What is going on here?

if ( 1 == 1) {

};

var local.result = {};

// add the page details to result
local.result['page'] = 1;
local.result['records'] = 2;
local.result['total'] = 3;

local.result['rows'] = [];

cfdrop( local.result );


Aug 11, 2011 at 7:56 PM // reply »
15 Comments

@Ben, @Ken,

Do you have a bug number of bug report for this? I'd like to vote it up. I lost quite a bit of time to this issue (see Stackoverflow: http://stackoverflow.com/questions/6948541/odd-coldfusion-behavior-abort-not-honored).

Thanks.

Aaron Greenlee


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 25, 2013 at 10:08 AM
Using "//" And ".//" Expressions In XPath XML Search Directives In ColdFusion
@Ben, my question is that i want the current node with its tag and its parent node. i just want only that data. So, give me the solution for that. and remember solution is working on " xpath 1.0 ... read »
May 25, 2013 at 10:01 AM
Using "//" And ".//" Expressions In XPath XML Search Directives In ColdFusion
hey ben, i want get my current node tag and also want the root node tag withing. So, how can i fix it.. ! ... read »
May 24, 2013 at 5:39 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
@Adam Oops! My mistake! I hadn't gotten that far in my testing - I'm still baby stepping my way through the process. ... read »
May 24, 2013 at 5:13 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
Hi Jason, Thanks for checking up on that, but I still stand firm on my position. :) There are actually two listLast()'s in use, and you're right that the one using a space as a delimiter is fine. ... read »
May 24, 2013 at 4:45 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
@Ben I have been lurking your site for quite some time, and haven't stepped up to comment until today. Thanks for all the great info - keep it up! @Adam I believe you are mistaken... as the commen ... read »
May 24, 2013 at 11:21 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@WebManWalking, Ha ha, let's us never speak of justifying "##" notation again :P ... read »
May 24, 2013 at 11:18 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, Ah, so it was indeed how I vaguely remembered it to be: A direct assignment value = users.id[ i ] causes value to retain the sticky datatype of the query column. Although unnecessary in ... read »
May 24, 2013 at 9:11 AM
Preventing Links In Standalone iPhone Applications From Opening In Mobile Safari
@Brandon, Hi, No, I haven't been able to do that. I have just kept it as it is. ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools