Wednesday, June 13, 2007

Obscure cf8 error message

While doing some work on a project that is currently running on cfmx, but which I'm testing on cf8, this strange error message appeared:

coldfusion.compiler.ASTsimpleVariableReference cannot be cast to java.lang.String

If you get this message, it's basically telling you that somewhere you've passed a variable or object where a string was expected. In my case, it was with a code bug that the previous versions of cf worked with but probably should have thrown an error. What I found was an indexed loop tag with a variable being used for the index. If you think about it, that really doesn't make sense. I don't think the author meant that the actual variable name would change as the loop executed or that it needed to change based on some value passed in.

<cfloop from="1" to="#upperLimit#" index="#myIndex#">

<cfloop from="1" to="#upperLimit#" index="myIndex">

What lead me to look at the loop was the stack trace that came along with the error. I don't know if anything else will cause this error, but the variable for an index string will cause it every time.


  1. I am getting the same error on this code:

    cfset myobj = CreateObject("Component", "Resources")

    Any ideas why?

    p.s.: i have removed the angle brackets just to make sure accepts my text.

  2. I think the code you posted looks ok, so I guess the next step is to dig into the component itself. Look for some place where you've passed a complex object to something expecting a simple string.

  3. Thanks for blogging this Mike

    It's probably obvious to note that if you are dealing with included files that the actual syntax error can often be contained within any files included by your script, not necessarily at the point where the compiler gives the error.

    Had me banjaxed for a while!

  4. Thanks Mike, this one really stummpped me. Like Dom it was deep in an included file so took some finding.

  5. Ha thanks, I can't believe I didn't notice myself!

  6. THANKS! I went right to the problem in the code after finding your post on the matter. Danke.

  7. Saved my ass too. I was trying to do this:

    [cfloop array="#loc.parameters#" index="#loc.parameter#"]

    Not so good. But also a not so good error message! I wonder if it was fixed in CF9.

  8. I found this site using [url=][/url] And i want to thank you for your work. You have done really very good site. Great work, great site! Thank you!

    Sorry for offtopic

  9. Thank you very much.

  10. Thanks for the article.

    FYI, this is not fixed in CF9.