Skip to main content
Participant
Apr 5, 2016 7:45 AM UTC
Question

java.math.BigDecimal cannot be cast to java.lang.String

this sentence below is working fine on Coldfusion 11 and previous version, but it throws exceptions when the application is deployed on Coldfusion 2016

Could anyone give some advice on this issue?

<cfset SubjectText = Replace(#SubjectText#,"%Request.RequestID%",#Request.RequestID#,"All")>

the value of #Request.RequestID# is a number

    This topic is closed to new replies. Start a new post to keep the conversation going.

    9 replies

    Inspiring
    Apr 25, 2016 10:55 PM UTC

    Definitely looks like I bug. I ran into the same issue. Like the error says, CF is failing to convert a BigDecimal to a string in order to use it in the replace function. This should work for you.

    <cfset SubjectText = Replace(SubjectText,"%Request.RequestID%",javaCast('String',Request.RequestID),"All")>

    For reference, here is an example that fails. In my case, the real value for the theBigDecimal was being generated by selecting an integer column from a simple query against Oracle. As you can see below, the javacast from bigdecimal to string works, but whatever it is doing in the replace function fails. I'll see if I can find were to file the bug.

    <cfscript>

    theBigDecimal = javaCast("bigdecimal", 123456);

    theBigDecimalasString = javaCast("String", theBigDecimal);

    newString = replace('This is my text with documentID in it','documentID',theBigDecimalasString);

    writeDump('This Works: ' & newString);

    writeDump('This Fails:');

    newString = replace('This is my text with documentID in it','documentID',theBigDecimal);

    </cfscript>

    Translate
    Inspiring
    Apr 25, 2016 11:01 PM UTC

    added to bug base

    Bug 4144890

    Translate
    Carl Von Stetten
    Legend
    Apr 5, 2016 3:57 PM UTC

    You shouldn't need the pound signs (#) around the variable Request.RequestID, although it appears to work even with them.

    Translate
    cjhxheAuthor
    Participant
    Apr 6, 2016 8:24 AM UTC

    i removed the pound , but still get the same error

    Translate
    Inspiring
    Apr 5, 2016 10:58 AM UTC

    Can you give exact examples of what you are using for each variable.

    I tried this and dont get any issues with it. - See Example http://trycf.com/gist/610a1e84aee0c490f4a2208296f890ee/acf2016?theme=monokai

    Translate
    cjhxheAuthor
    Participant
    Apr 6, 2016 8:23 AM UTC

    yes it works in CF 11 and previous versions but  not working in CF 12

    Translate