Skip to content

Commit

Permalink
8301065: Handle control characters in java_lang_String::print
Browse files Browse the repository at this point in the history
Backport-of: 41d6be4d807921a91339029ae96e8dc14561bea6
  • Loading branch information
Andrew Lu authored and GoeLin committed Sep 27, 2023
1 parent bcac47f commit c2ac5e2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/hotspot/share/classfile/javaClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,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("\"");
}
Expand Down

1 comment on commit c2ac5e2

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.