StringBuilder.length() does not work with Adobe CF and JDK 1.6.X


StringBuilder.length() does not work with Adobe CF and JDK 1.6.X

Posted by Luis Majano
Aug 11, 2008 00:00:00 UTC
I have been doing some string buffer testing and wanted to take advantage of using the new class StringBuilder that was implemented in jdk 1.5. I am running cf8 with jdk 1.5 and 1.6 and decided to do some tests with it. I found out that calling buffer.length() on a cf instance running on jdk 1.6 would fail but a call to the same length method on jdk 1.5 does not. Go Figure!!

Would this be a bug on the Adobe cf java proxy? It seems to me, because the same tests on Railowork (even faster to say the least)!!

To reproduce this error, just try this below:

The string is #myBuffer.toString()#

The length is #myBuffer.length()#

The error that Adobe CF produces is that the method length() does not exist. The only workaround for this is by lengthing the string produced, but it will definitely be slower than a direct length call:

Length: #myBuffer.toString().length()#

 


Ben Nadel

Have you tried using StringBuffer rather than StringBuilder? I know this doesn't really address your issue, but I have definitely run into StringBuilder issues in the past in CF. When switching over to StringBuffer, I have not had any problems at all.

Probably not helpful, but just a thought.

Luis Majano

Thanks Ben!!

I use StringBuffer a lot also, but by the JDK specs, StringBuilder is suppossed to be much faster and taking over StringBuffer, so I was hoping to use it more!!

But yes you are right on the money, StringBuffer gives zero problems!!

Ben Nadel

Sweeeeet.

Larry C. Lyons

From what I understand String Buffer may be a better choice to use. Not only doe it have the same API as the StringBuilder, but its also thread-safe, since its is designed to be thread-safe and all public methods in StringBuffer are synchronized. StringBuilder does not handle thread-safety issue and none of its methods is synchronized. That said StringBuilder is supposed to have better performance than StringBuffer, but for StringBuilder you need millions of iterations to really see a difference. And those differences typically are less than OS or hardware factors.

So in the end, StringBuffer may be better for 90% of all uses.

Peter J. Farrell

FYI, the same goes for substring() in StringBuilder on Adobe CF on 1.6 series JVMs.

Gabriel

If you cfdump a StringBuilder object, it will show you which methods are supported.

Several others are missing although in the "parent class" in the dump, it has all of them.

Deinfitely weird. Using StringBuffer in the meantime.

  • Gabriel

Site Updates

Entry Comments

Archives

Entries Search