tracker issue : CF-3037908

select a category, or use search below
(searches all categories and all time range)
Title:

Bug 76016:cfproperty declaration in component interferes with inheritance

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Joel Cox / Joel Cox (jlcox)

Created: 03/16/2009

Components: Language, CF Component

Versions: 9.0

Failure Type: Unspecified

Found In Build/Fixed In Build: 0000 / 227818

Priority/Frequency: Major / Unknown

Locale/System: English / Win All

Vote Count: 0

Problem:

cfproperty declaration in component interferes with inheritance.

beanB extends beanA. beanB adds FieldC to FieldA and FieldB declared in beanA. beanB contains cfproperty declarations for FieldA, FieldB, and FieldC. If beanB is populated using setters for FieldA, FieldB, and FieldC, only FieldC is properly set. Removing the cfproperty declarations results in the expected behavior.

Method:

/**** beanA ****/
<cfcomponent displayname="beanA">
  
  <cffunction name="init" access="public" returntype="beanA" output="false" displayname="component 'Constructor'" hint="I initialize this component.">
    <cfargument name="FieldA" displayname="string FieldA" hint="initial value for the FieldA property" type="string" required="no" default="" />
    <cfargument name="FieldB" displayname="string FieldB" hint="initial value for the FieldB property" type="string" required="no" default="" />
    <cfscript>
        variables.instance = structNew();
        variables.instance.FieldA = arguments.FieldA;
        variables.instance.FieldB = arguments.FieldB;
    </cfscript>
    <cfreturn this />
  </cffunction>
  
  <!--- standard getter/setter methods --->
  <cffunction name="getFieldA" displayname="string getFieldA()" hint="get the value of the FieldA property" access="public" output="false" returntype="string">
    <cfreturn variables.instance.FieldA />
  </cffunction>
  
  <cffunction name="setFieldA" displayname="setFieldA(string newFieldA)" hint="set the value of the FieldA property" access="public" output="false" returntype="void">
    <cfargument name="newFieldA" displayname="numeric newFieldA" hint="new value for the FieldA property" type="string" required="yes" />
    <cfset variables.instance.FieldA = arguments.newFieldA />
  </cffunction>
  
  <cffunction name="getFieldB" displayname="string getFieldB()" hint="get the value of the FieldB property" access="public" output="false" returntype="string">
    <cfreturn variables.instance.FieldB />
  </cffunction>
  
  <cffunction name="setFieldB" displayname="setFieldB(string newFieldB)" hint="set the value of the FieldB property" access="public" output="false" returntype="void">
    <cfargument name="newFieldB" displayname="numeric newFieldB" hint="new value for the FieldB property" type="string" required="yes" />
    <cfset variables.instance.FieldB = arguments.newFieldB />
  </cffunction>
  
  <!--- standard get instance method --->
  <cffunction name="getInstance" displayname="struct getInstance()" hint="get struct instance of the bean" access="public" returntype="struct" output="false">
    <cfreturn variables.instance />
  </cffunction>
  
  <!--- standard set instance method --->
  <cffunction name="setInstance" displayname="setInstance(struct newInstance)" hint="set struct instance of the bean" access="public" returntype="void" output="false">
    <cfargument name="newInstance" displayname="struct newInstance" hint="new instance for the bean" type="struct" required="yes" />
    <cfset variables.instance = arguments.newInstance />
  </cffunction>
  
</cfcomponent>

/**** end beanA *****/

/**** beanB *****/
<cfcomponent displayname="beanB" hint="beanB, extends beanA" extends="beanA">
  
  <cfproperty name="FieldA" type="string" />
  <cfproperty name="FieldB" type="string" />
  <cfproperty name="FieldC" type="string" />
  <cffunction name="init" access="public" returntype="beanB" output="false" displayname="component 'Constructor'" hint="I initialize this component.">
    <cfargument name="FieldA" displayname="string FieldA" hint="initial value for the FieldA property" type="string" required="no" default="" />
    <cfargument name="FieldB" displayname="string FieldB" hint="initial value for the FieldB property" type="string" required="no" default="" />
    <cfargument name="FieldC" displayname="string FieldC" hint="initial value for the FieldC property" type="string" required="no" default="" />
    <cfscript>
        super.init(arguments.FieldA, arguments.FieldB);
        variables.instance.FieldC = arguments.FieldC;
    </cfscript>
    <cfreturn this />
  </cffunction>
  
  <!--- standard getter/setter methods --->
  <cffunction name="getFieldC" displayname="string getFieldC()" hint="get the value of the FieldC property" access="public" output="false" returntype="string">
    <cfreturn variables.instance.FieldC />
  </cffunction>
  
  <cffunction name="setFieldC" displayname="setFieldC(string newFieldC)" hint="set the value of the FieldC property" access="public" output="false" returntype="void">
    <cfargument name="newFieldC" displayname="numeric newFieldC" hint="new value for the FieldC property" type="string" required="yes" />
    <cfset variables.instance.FieldC = arguments.newFieldC />
  </cffunction>
  
</cfcomponent>

/**** end beanB *****/

/**** serviceComp *****/
<cfcomponent>
  
  <cffunction name="init" returntype="serviceComp">
  	<cfreturn this />
  </cffunction>
  
  <cffunction name="myFunction" access="public" returntype="struct">
    <cfargument name="beanB" type="beanB" required="yes">
    <cfreturn beanB.getInstance()>
  </cffunction>
  
</cfcomponent>

/**** end serviceComp *****/

/**** tester.cfm ******/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
	<cfset obj = CreateObject("component", "serviceComp").init() />
    <cfset bean = CreateObject("component", "beanB").init() />
    <cfset bean.setFieldA("one") />
    <cfset bean.setFieldB("two") />
    <cfset bean.setFieldC("three") />
    <cfset x = obj.myFunction(bean) />
    <cfdump var="#x#">

    <!---FieldA and FieldB are empty.
    now remove the 3 cfproperty declarations at the top of beanB.
    all 3 should be populated--->
</body>
</html>
/**** end tester*****/
Result:

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3037908

External Customer Info:
External Company:  
External Customer Name: Joel Cox
External Customer Email: 17A0291744608F7A9920157F
External Test Config: 03/16/2009

Attachments:

Comments: