8301065: Handle control characters in java_lang_String::print

Reviewed-by: iklam, dholmes
This commit is contained in:
Kevin Walls 2023-04-24 16:33:54 +00:00
parent 4b23bef51d
commit 41d6be4d80

View File

@ -765,8 +765,13 @@ void java_lang_String::print(oop java_string, outputStream* st) {
st->print("\"");
for (int index = 0; index < length; index++) {
st->print("%c", (!is_latin1) ? value->char_at(index) :
((jchar) value->byte_at(index)) & 0xff );
jchar c = (!is_latin1) ? value->char_at(index) :
((jchar) value->byte_at(index)) & 0xff;
if (c < ' ') {
st->print("\\x%02X", c); // print control characters e.g. \x0A
} else {
st->print("%c", c);
}
}
st->print("\"");
}