[Coldfusion 10] Serious component bug

Hi Guys,

I know this is not the place for Coldfusion 10 bugs, but I thought I should give you a heads up…

Random component MyTest.cfc:

/**

  • I am Test
    */
    component accessors=“true” {

property name=“privateVarOne” default=“privateVarOne default”;

function init() {
return this;
}

public void function newMethod() {
var myVar = variables.privateVarOne;
writedump(var=“success”);
}
}

Nothing fancy right?

Call component:

<cfset test = new MyTest() />

<cfset test.newMethod() />

outputs the component followed by success; = expected behaviour.

Call component without dump:

<cfset test = new MyTest() />
<cfset test.newMethod() />

throws:

The web site you are accessing has experienced an unexpected error.
Please contact the website administrator.

The following information is meant for the website developer for debugging purposes.

Error Occurred While Processing Request

Element PRIVATEVARONE is undefined in VARIABLES.

The error occurred in E:/www/development/testGround/MyTest.cfc: line 13

11 : 	
12 : 	public void function newMethod() {
**13 : 		var myVar = variables.privateVarOne;**
14 : 		writedump(var="success");
15 : 	}

I think you will find that the problem is that you are using the property name to set the variable, ColdFusion will set that into the scope this and not variables.

Hi Andrew,

Nope properties go by default to the private variables scope.
The this scope is for public variables.

You can test this by initializing properties in the init function (which is by the way a work around for this problem; so not to rely on default values of properties)

The bug is that properties with a default value are not being populated into the variables struct.
You can initialize using one of three methods in the init function:

variables.privateVarOne = “privateVarOne initial variables struct”;
privateVarOne = “privateVarOne initial default variables struct”;
setPrivateVarOne(“privateVarOne initial setter”);

All three methods will set variables struct.

Here is a test you can use:

component accessors=“true” {

property name=“privateVarOne” type=“string” default=“privateVarOne default” setter=“true”;
property name=“privateVarTwo” type=“string” default=“privateVarTwo default”;

function init() {
var filePath = “e:\www\development\test.html”;
if(fileExists(filePath)) {
fileDelete(filePath);
}

writeDump(var=“dumping this with only default values”, output=filePath, format=“html”);
writeDump(var=this, output=filePath, format=“html”);

writeDump(var=“dumping variables with only default values”, output=filePath, format=“html”);
writeDump(var=variables, output=filePath, format=“html”);

this.onePublicVariable = “onePublicVariable initial”;

/*
writeDump(var=“setting privates using variables struct”, output=filePath, format=“html”);
variables.privateVarOne = “privateVarOne initial variables struct”;
variables.privateVarTwo = “privateVarTwo initial variables struct”;
/
/

writeDump(var=“setting privates using default struct”, output=filePath, format=“html”);
privateVarOne = “privateVarOne initial default struct”;
privateVarTwo = “privateVarTwo initial default struct”;
*/
writeDump(var=“setting privates using setters”, output=filePath, format=“html”);
setPrivateVarOne(“privateVarOne initial setter”);
setPrivateVarTwo(“privateVarTwo initial setter”);

writeDump(var=“dumping this with initial values”, output=filePath, format=“html”);
writeDump(var=this, output=filePath, format=“html”);

writeDump(var=“dumping variables with initial values”, output=filePath, format=“html”);
writeDump(var=variables, output=filePath, format=“html”);
return this;
}

public void function newMethod() {
var myVar = variables.privateVarOne;
}

public struct function getVariables() {
return variables;
}
}

Cheers,
Tom

And you will also see that in the init function CF does see the default values… it is in the other methods that the default value somehow magically gets lost.

I have seen this issue since cf9 where the default property does nothing on normal cfcs but works on orm entities. Maybe you should submit this to adobe Tom!

Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Social: twitter.com/ortussolutions | twitter.com/coldbox | twitter.com/lmajano

Hi Luis,

Did that yesterday :wink:

https://bugbase.adobe.com/index.cfm?event=bug&id=3352745

Cheers,
Tom