SwiftMango
SwiftMango

Reputation: 15284

Long string convert to UTF-8 throws exception

I am using GWT, and have a very long string from RichTextArea and I want to convert it to UTF-8 before sending to the server:

String content = new String(rta.getText().getBytes(), "UTF-8");

However this one throws an exception saying:

 [Range Error]: Maximum call stack size exceeded

Is this a bug?

Upvotes: 0

Views: 222

Answers (1)

Brett Okken
Brett Okken

Reputation: 6306

RichTextArea.getText returns a String. The operation you are doing to "convert to utf-8" is not correct. There is no need to convert a java String to any character encoding. The code you have is getting the bytes in the default character encoding of the platform and then interpreting them as utf-8. At best this is a lot of work to get back to the exact same String. At worst (say platform encoding of utf-16le) you mangle your String data completely.

Upvotes: 1

Related Questions