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

New Here ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

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

Views

3.4K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 06, 2016 Apr 06, 2016

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 06, 2016 Apr 06, 2016

Copy link to clipboard

Copied

firstly i get the result from db:

<cfquery name="Request" DATASOURCE="WES" >

SELECT *

FROM REQUEST

WHERE RequestID = #RequestID#

</cfquery>

then do the replace of some text template

.....

.....

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 06, 2016 Apr 06, 2016

Copy link to clipboard

Copied

What are the actual values though? What does SubjectText and RequestID represent?

If you replace these with the actual values does the same thing happen?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 06, 2016 Apr 06, 2016

Copy link to clipboard

Copied

The first thing that I noticed (and this may or may not be part of the issue) is that you are naming the query object using a reserved word: request (as in the request scope.)

<cfset SubjectText = replace(SubjectText,"%Request.RequestID%",Request.RequestID,"all") />

Are you only trying to take an ID number surrounded by percent signs and remove the percent signs?

EDIT:  Seems to me that if you're just trying to remove the percent signs, then nested inside the percent signs should be hashmarks because the variable is contained within string demarcation.

<cfset SubjectText = replace(SubjectText,"%#Request.RequestID#%",Request.RequestID,"all") />

^_^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 06, 2016 Apr 06, 2016

Copy link to clipboard

Copied

i removed the pound , but still get the same error

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 25, 2016 Apr 25, 2016

Copy link to clipboard

Copied

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>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 25, 2016 Apr 25, 2016

Copy link to clipboard

Copied

LATEST

added to bug base

Bug 4144890

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines