8257511: JDK-8254082 brings regression to AbstractStringBuilder.insert(int dstOffset, CharSequence s, int start, int end)

Reviewed-by: alanb, rriggs, bpb
This commit is contained in:
Claes Redestad 2020-12-01 22:50:05 +00:00
parent 015e6e58c5
commit 00e79db89e
2 changed files with 25 additions and 9 deletions
src/java.base/share/classes/java/lang
test/jdk/java/lang/StringBuilder

@ -1717,7 +1717,7 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
if (getCoder() != str.coder()) {
inflate();
}
str.getBytes(value, off, index, coder, end);
str.getBytes(value, off, index, coder, end - off);
}
private void putStringAt(int index, String str) {

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,15 +21,31 @@
* questions.
*/
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
/**
* @test
* @bug 4914802
* @summary Test Insert method for infinite loop
* @run testng Insert
* @bug 4914802 8257511
* @summary Test StringBuilder.insert sanity tests
*/
@Test
public class Insert {
public static void main (String argv[]) throws Exception {
StringBuilder sb = new StringBuilder();
sb.insert(0, false);
}
public void insertFalse() {
// Caused an infinite loop before 4914802
StringBuilder sb = new StringBuilder();
assertEquals("false", sb.insert(0, false).toString());
}
public void insertOffset() {
// 8254082 made the String variant cause an AIOOBE, fixed in 8257511
assertEquals("efabc", new StringBuilder("abc").insert(0, "def", 1, 3).toString());
assertEquals("efabc", new StringBuilder("abc").insert(0, new StringBuilder("def"), 1, 3).toString());
// insert(I[CII) and insert(ILjava/lang/CharSequence;II) are inconsistently specified
assertEquals("efabc", new StringBuilder("abc").insert(0, new char[] {'d', 'e', 'f'}, 1, 2).toString());
}
}