java.lang.ClassCastException (cannot cast to lucee.transformer.bytecode.expression.var.NamedArgument) during Startup / ORM load

Hi,

after a restart (without changing my orm settings or my persistent cfcs) i get this Exception:

lucee.runtime.exp.NativeException: lucee.transformer.bytecode.expression.var.Argument cannot be cast to lucee.transformer.bytecode.expression.var.NamedArgument
  at lucee.transformer.bytecode.expression.var.VariableImpl.toNamedArguments(VariableImpl.java:777)
  at lucee.transformer.bytecode.expression.var.VariableImpl._writeOutFirstBIF(VariableImpl.java:388)
  at lucee.transformer.bytecode.expression.var.VariableImpl._writeOutFirst(VariableImpl.java:363)
  at lucee.transformer.bytecode.expression.var.VariableImpl._writeOut(VariableImpl.java:224)
  at lucee.transformer.bytecode.expression.var.VariableImpl._writeOut(VariableImpl.java:202)
  at lucee.transformer.bytecode.expression.ExpressionBase.writeOutAsType(ExpressionBase.java:62)
  at lucee.transformer.bytecode.statement.ExpressionAsStatement._writeOut(ExpressionAsStatement.java:61)
  at lucee.transformer.bytecode.statement.StatementBase.writeOut(StatementBase.java:81)
  at lucee.transformer.bytecode.util.ExpressionUtil.writeOut(ExpressionUtil.java:134)
  at lucee.transformer.bytecode.BodyBase.writeOut(BodyBase.java:191)
  at lucee.transformer.bytecode.BodyBase.writeOut(BodyBase.java:147)
  at lucee.transformer.bytecode.BodyBase._writeOut(BodyBase.java:143)
  at lucee.transformer.bytecode.statement.StatementBase.writeOut(StatementBase.java:81)
  at lucee.transformer.bytecode.statement.Condition._writeOut(Condition.java:120)
  at lucee.transformer.bytecode.statement.StatementBase.writeOut(StatementBase.java:81)
  at lucee.transformer.bytecode.util.ExpressionUtil.writeOut(ExpressionUtil.java:134)
  at lucee.transformer.bytecode.BodyBase.writeOut(BodyBase.java:191)
  at lucee.transformer.bytecode.BodyBase.writeOut(BodyBase.java:147)
  at lucee.transformer.bytecode.BodyBase._writeOut(BodyBase.java:143)
  at lucee.transformer.bytecode.FlowControlBody._writeOut(FlowControlBody.java:39)
  at lucee.transformer.bytecode.statement.StatementBase.writeOut(StatementBase.java:81)
  at lucee.transformer.bytecode.statement.NativeSwitch._writeOut(NativeSwitch.java:74)
  at lucee.transformer.bytecode.Page.writeOutUdfCallInner(Page.java:853)
  at lucee.transformer.bytecode.Page.execute(Page.java:523)
  at lucee.runtime.compiler.CFMLCompilerImpl._compile(CFMLCompilerImpl.java:130)
  at lucee.runtime.compiler.CFMLCompilerImpl.compile(CFMLCompilerImpl.java:76)
  at lucee.runtime.PageSourceImpl._compile(PageSourceImpl.java:402)
  at lucee.runtime.PageSourceImpl.compile(PageSourceImpl.java:369)
  at lucee.runtime.PageSourceImpl.loadPhysical(PageSourceImpl.java:329)
  at lucee.runtime.PageSourceImpl.loadPage(PageSourceImpl.java:201)
  at lucee.runtime.component.ComponentLoader.loadPage(ComponentLoader.java:440)
  at lucee.runtime.util.TemplateUtilImpl.loadPage(TemplateUtilImpl.java:76)
  at org.lucee.extension.orm.hibernate.HibernateSessionFactory.loadComponents(HibernateSessionFactory.java:447)
  at org.lucee.extension.orm.hibernate.HibernateSessionFactory.loadComponents(HibernateSessionFactory.java:417)
  at org.lucee.extension.orm.hibernate.HibernateSessionFactory.loadComponents(HibernateSessionFactory.java:422)
  at org.lucee.extension.orm.hibernate.HibernateSessionFactory.loadComponents(HibernateSessionFactory.java:422)
  at org.lucee.extension.orm.hibernate.HibernateSessionFactory.loadComponents(HibernateSessionFactory.java:399)
  at org.lucee.extension.orm.hibernate.HibernateSessionFactory.loadComponents(HibernateSessionFactory.java:379)
  at org.lucee.extension.orm.hibernate.HibernateORMEngine.getSessionFactoryData(HibernateORMEngine.java:131)
  at org.lucee.extension.orm.hibernate.HibernateORMEngine.init(HibernateORMEngine.java:69)
  at lucee.runtime.config.ConfigImpl.getORMEngine(ConfigImpl.java:3131)
  at lucee.runtime.config.ConfigImpl.resetORMEngine(ConfigImpl.java:3115)
  at lucee.runtime.orm.ORMUtil.resetEngine(ORMUtil.java:74)
  at lucee.runtime.tag.Application.doStartTag(Application.java:647)
  at backoffice.application_cfm$cf.call(/backoffice/application.cfm:46)

Lucee 5.3.2.77
Apache Tomcat/8.5.35
1.8.0_31 (Oracle Corporation) 64bit
Windows 8.1 (6.3) 64bit

Are there some generated file i can delete or what is the problem?
Setting ormenabled=false in the application.cfm solved the issues but i stil want to use the ORM :slight_smile:

Kind regards
Michael

I finally found the error. The cause was a syntax error in a cfc file which is in the same folder like 3 persistent objects.

Error line was:

arrayAppend(calls, "tz" = tzLoc, "locationId" = value);

Correct Version:

arrayAppend(calls, {"tz" = tzLoc, "locationId" = value});

WEIRED. Would be really great to have a better syntax checking mechanism on board. Coming from java/eclipse it takes about 1sec while coding to see this error. With sublime there was no hint and the exception was meaningless…

Kind regards
Michael

lucee.runtime.exp.NativeException: lucee.transformer.bytecode.expression.var.Argument cannot be cast to lucee.transformer.bytecode.expression.var.NamedArgument

is saying there’s a problem with a namedArgument

what’s the exception without the quotes around “tz” and “locationId” ?

Hmm with this (wrong) code:

arrayAppend(calls, tz = tz, locationId = "0"});

i get an normal error message:

So: Is it “bad style” to quote the attribute names of a struct or why do i get such a unprecise error message as in my first post? Especially confusing was that the error was thrown during the orm initialization…

Kind regards
Michael

I wouldn’t say quoting the key in a structure is bad style. Both are valid. It more depends on your intent. For example, if I want the case of the key to be maintained versus Lucee resorting to an all caps styling in other representations of the dataset down the line. Personally, if I am not presenting the key as a string (JSON etc.), I tend to omit the quotes.

Now regarding the error message between your scenarios. I understand the messages can appear vague at times, but they are still relevant to the actual issue in both examples…

Since the first syntax error makes the key/value pairs appear as arguments, the exception points out there was an issue evaluating the arguments passed. Regardless of the quotes, tz and locationId are not valid arguments of the 3 allowed in arrayAppend(). I can understand it would be nice if perhaps the message was more specific as to which argument it tripped up on but if it at least gave a line number, that’s a great start. Anything more specific is the job of your IDE ahead of time in my opinion.

The second exception is a little different since the closing } is involved. I assume the parser attempts to make use of it when looking at the entire block encapsulating the array function before evaluating the function itself (e.g. if {}). Since it would see that as the end of a block, arrayAppend() is never evaluated to be closed as the ) is ignored; hence the error. The message paired with the highlighted line is about as precise as I think it could be beyond an IDE parsing the syntax or running a linter ahead of execution.

I certainly don’t claim to know how Lucee parses over the code so this is just my assumption from a very open view of it all. ORM is a whole other beast, and I’ve never been a fan of the error handling / stack traces produced from it in any CFML engine. Which is also why I stopped using it years ago in projects :sweat_smile:.

Cheers.

Thanks for clarifications…

Preserving the case for the key was the reason why I had choosen to use quotes…

Only thing on my wish list is the point that the exception or a log message before this exception) tells me which cfc contains the error or in the best case the line… :slight_smile:

Kind regards
Michael

yep, good idea, file a bug

bug filed [LDEV-3238] - Lucee

1 Like