Thursday, 20 November 2014

Railo "unexpected" behaviour: opinions solicited

This will be one of those really quick ones as I have precisely 19min of lunchtime left to write it.

Ryan Guill found some oddness with Railo yesterday, with code like this:

function tikiOtinga(required string s required numeric i){

(his example wasn't in Maori, but hey).

Can you spot what's wrong with it?

Here's a call to the function, and its output:

function tikiOtinga(required string s required numeric i){

tikiOtinga("Whā tekau mā rua", 42);

Erm hello?

OK, look more closely and the function spec:

function tikiOtinga(required string s required numeric i)

It's missing a comma.

So how does this even compile, and what is it doing? The same code on CF gives predictable results:

The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request

Attribute validation error.

A duplicate attribute REQUIRED has been encountered. Attributes with the same name cannot be provided more than once.The CFML compiler was processing:

  • A script statement beginning with function on line 3, column 9.
  • A cfscript tag beginning on line 2, column 2.
The error occurred in functionMetadata.cfm: line 3
1 : <cfprocessingdirective pageEncoding="utf-8">
2 : <cfscript>
3 :  function tikiOtinga(required string s required numeric i){
4 :   writeDump(arguments);
5 :  }

This is correct behaviour in my view.

Ryan was puzzled, but he found ticket RAILO-2638, in which Micha says this:

Thx for the input and the effort for this ticket, but i'm sorry, i have to disagree.
This way you simply declare hints.
add the following to your testcode and you will see:
you define named hints without a value, do the following code and it will be even more clear
function a (numeric a,numeric b,numeric c numeric="Susi" d="Sorglos",numeric e)
{ writeDump(arguments); }
btw: ACF acts exact the same way
This is nonsense, IMO. Not least of all because the last statement is not correct: CF baulks at this.

What Micha means is that one can specify additional metadata against arguments (although doing it this way is quite crap, but that is a story for another day), but - on ColdFusion anyhow, it knows an error when it sees it: one cannot have metadata keys that are "reserved" values.

This simply should not compile.

Note: this doesn't compile even on Railo:

<cffunction name="tikiOtinga">
    <cfargument required="true" type="string" name="s" required="" numeric="" i="">

(which is directly analogous to the script version).

I think whilst one might be able to specify additional metadata fields on an argument, one should not be permitted to use keywords as their names in this context.

CF gets it right: Railo gets it wrong.