Skip to content

Commit

Permalink
Fix ClassCastException when using StringBuilder/Buffer mozilla#496
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Jensen committed May 19, 2022
1 parent 8340c26 commit 88de68f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/org/mozilla/javascript/ConsString.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public class ConsString implements CharSequence, Serializable {
private boolean isFlat;

public ConsString(CharSequence str1, CharSequence str2) {
if (!(str1 instanceof String) && !(str1 instanceof ConsString)) {
str1 = str1.toString();
}
if (!(str2 instanceof String) && !(str2 instanceof ConsString)) {
str2 = str2.toString();
}
left = str1;
right = str2;
length = left.length() + right.length();
Expand Down Expand Up @@ -69,7 +75,7 @@ private synchronized String flatten() {
}
}

final String str = next.toString();
final String str = (String) next;
charPos -= str.length();
str.getChars(0, str.length(), chars, charPos);
next = stack.isEmpty() ? null : stack.removeFirst();
Expand Down

0 comments on commit 88de68f

Please sign in to comment.