Skip to main content
January 24, 2011
Question

Struct shorthand notation

  • January 24, 2011
  • 3 replies
  • 1702 views

Hi,

Suppose I have the following function in a CFC:

<cffunction name="getStruct" >

      <cfargument name="arg" type="struct">

.....

</cffunction>

I can use the following to pass a struct into the above function.

<cfset obj.getStruct( {x="abc"} )>

However, when I include the name of the argument

<cfset obj.getStruct( arg = {x="abc"} )>

I get the error

java.lang.IllegalStateException: no parent

Any idea why the error?



    This topic has been closed for replies.

    3 replies

    BKBK
    Community Expert
    Community Expert
    January 26, 2011

    I don't think it has to do with the difference between invoking with {x="abc"} or with arg = {x="abc"}. The exception is telling you that your component instance (Obj) was in an illegal or inconsistent state when it made the second call to getStruct. You probably had a series of inconsistent getStruct calls.

    Test the hypothesis as follows.

    TestComp.cfc

    <cfcomponent>

    <cffunction name="getStruct" returntype="struct">
          <cfargument name="arg" type="struct">
        <cfreturn arguments.arg>
    </cffunction>

    </cfcomponent>

    testpage.cfm

    <cfset obj = createobject("component", "TestComp")>

    <cfset str1 = obj.getStruct( {x="abc"} )>
    <cfset str2 = obj.getStruct( arg = {x="abc"} )>

    <cfdump var="#str1#" label="str1">
    <cfdump var="#str2#" label="str2">

    January 27, 2011

    Thank you all for your help.  I wasn't sure whether the version I had included the update, so thanks for the clarification. It seems that i just need to get the server updated to fix the bug.

    @BKBK: I tried your code and it gives the same error on the server. 

    Sincerely,

    ML

    BKBK
    Community Expert
    Community Expert
    January 27, 2011

    minli98 wrote:

    Thank you all for your help.  I wasn't sure whether the version I had included the update, so thanks for the clarification. It seems that i just need to get the server updated to fix the bug.

    @BKBK: I tried your code and it gives the same error on the server. 

    I am on 9.0.1. As others have suggested, this is very likely a bug in ColdFusion 9.0.0.

    12Robots
    Participating Frequently
    January 26, 2011

    If I am reading the release notes correctly, it looks like this was fixed in 9.0.1

    http://kb2.adobe.com/cps/847/cpsid_84726.html

    Search for bug number 80335

    Inspiring
    January 26, 2011

    Yeah, they did improve support for inline structs in 9.0.1.  However the OP said this:

    minli98 wrote:

    I tested it on my local computer and the server.  Both are running 9,0,0,251028.  On my local computer, the code f( arg = {x="abc"}) runs fine, but the server throws the error I mentioned.

    I dunno whether 251028 is 9.0 or 9.0.1, but both his boxes are the same version...

    --

    Adam

    12Robots
    Participating Frequently
    January 26, 2011

    I know what the OP wrote, that's why I answered the question.

    9.0.1 is 9,0,1,274733 and the problem with passing named inline structs was addressed in that version, according to the release notes.

    Inspiring
    January 24, 2011

    Which version of CF?  The support for this notation was patching in CF8... I think generally you need to assign the struct to a variable, then pass the variable, as opposed tousing the {} notation directly in the argument value.  EG:

    st = {key="val"};

    x = f(arg=st);

    instead of:

    x = f(arg=key="val");

    This has been improved in CF9, but it's not completely implemented properly yet, from memory.

    --

    Adam

    January 24, 2011

    I tested it on my local computer and the server.  Both are running 9,0,0,251028.  On my local computer, the code f( arg = {x="abc"}) runs fine, but the server throws the error I mentioned.

    Inspiring
    January 26, 2011

    Odd.

    I don't have CF9 in front of me to do any testing with, sorry.

    If you create the struct first... ie: assign it to a variable and pass the variable, do you get the same problem?

    --

    Adam