A Unique Developer

java.lang.Double cannot be cast to java.lang.String

"java.lang.Double cannot be cast to java.lang.String" error you must face if you are previously using ColdFusion 8 and migrating to ColdFusion 9. For one of my client we were migrating from CF8 to CF9, mainly we faces issue related to ExtJs as CF 9 using 3.0 version which I can understand but above error really surprised me as this one is coldfusion error and I found nothing wrong in my code as that was working fine in ColdFusion 8. After googling on I found it was bug and Adobe has consider as hot fixes. 

Let me write small example to demonstrate this issue. Two test files CallMath.cfm and Math.cfc


<cfcomponent output="false">      <cffunction name="add" returntype="numeric" access="remote">            <cfargument name="val1" required="true" type="numeric">            <cfargument name="val2" required="true" type="numeric">            <cfreturn val1 + val2>     </cffunction></cfcomponent>

simple cfc with function ADD to return addition of two numbers and obviously I will keep return type numeric for this.


<cfajaxproxy cfc="test.math" jsclassname="math"><html>   <head>     <script type="text/javascript">        var objMath = new math();        function addNumber(a,b,atag)        {           c = objMath.add(a,b);           atag.innerHTML = c;        }     </script>    </head>    <body>        5 + 6 = <a href="#" onclick="addNumber(5,6,this)">Click here for Answer</a>    </body></html>

In this file I have created proxy object for math.cfc and try to call add function to get answer in JSON format. By clicking on link will give ParseJSON javascript error because in this case you get java.lang.Double cannot be cast to java.lang.String error. 


Solution is really simple, just change return type of function ADD to string and it will start working fine. I know this is not perfect solution as I won't like to keep return type String when I know it is always return numeric value.

Adobe recently launch Hot Fix1 which include fix for this issue as well.