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

Posted July 30, 2009 at 1:40 PM

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:

 Launch code in new window » Download code as text file »

  • <!--- 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:

 Launch code in new window » Download code as text file »

  • <!--- 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.

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Other Searches  |  Print Page


You Might Also Be Interested In:




Reader Comments

Jul 30, 2009 at 1:49 PM // reply »
7,572 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.


Post Comment  |  Ask Ben

Recent Blog Comments
Mar 20, 2010 at 12:07 PM
Drawing On The iPhone Canvas With jQuery And ColdFusion
Simply awesome. Saved my day. ... read »
Mar 20, 2010 at 9:00 AM
Building A Fixed-Position Bottom Menu Bar (ala FaceBook)
I would like to say thx for an easy way to create a bottom bar. I do have a ?. Is it possible to center the bar if i want to resize it to ex 85%. Regards Offenbach ... read »
Mar 19, 2010 at 7:26 PM
MySQL 3/4 - com.mysql.jdbc.Driver And allowMultiQueries=true
Thank you very much for this post. Adding allowMultiQueries="true" in context.xml didn't help until I added it to url as allowMultiQueries=true Good idea is to use prepared statements and it will he ... read »
Jim
Mar 19, 2010 at 4:49 PM
Nobody Puts Baby In The Corner!
Wow. This is like suddenly finding a support group for your secret shame. I'm not alone! I always liked this movie, even though it is extremely cheesy. I just wish Jennifer Grey hadn't gotten the ... read »
Mar 19, 2010 at 4:47 PM
Application.cfc OnRequest() Method Affects OnError() Arguments
@Jason and @Ben, I've been doing some CF9 refactoring on our systems and noticed an odd occurrence with onError as well. Found a way to work around my problem, but what I saw was... Background: Our ... read »
Jim
Mar 19, 2010 at 4:44 PM
Shoot 'Em Up Starring Clive Owen And Paul Giamatti
I actually enjoyed this movie quite a lot. It was different, certainly, but I think they were going for more of a Quentin Tarentino-"wow, that was weird"-vibe than an actual spoof. Once I realize ... read »
Mar 19, 2010 at 4:34 PM
An Intensive Exploration Of jQuery With Ben Nadel (Video Presentation)
Hey I guess the video is down. Is there anyway you can upload to youtube or vimeo or some other service? Greatly appreciated. ... read »
Mar 19, 2010 at 4:24 PM
ColdFusion CFPOP - My First Look
@Ben Thanks for the follow up! The root of the problem had to do with being able to trace bounced emails to specific records in a DB table. Let's say you run an email campaign and you get 1,000 bou ... read »