Skip to content

Commit 254a2c1

Browse files
authored
Use StringBuilder instead of StringBuffer (elastic#128665) (elastic#128744)
1 parent 52df16d commit 254a2c1

File tree

9 files changed

+16
-16
lines changed

9 files changed

+16
-16
lines changed

modules/lang-painless/src/main/java/org/elasticsearch/painless/api/Augmentation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,10 @@ public static <K, V, T> Map<T, Map<K, V>> groupBy(Map<K, V> receiver, BiFunction
456456
public static String replaceAll(CharSequence receiver, Pattern pattern, Function<Matcher, String> replacementBuilder) {
457457
Matcher m = pattern.matcher(receiver);
458458
if (false == m.find()) {
459-
// CharSequqence's toString is *supposed* to always return the characters in the sequence as a String
459+
// CharSequence's toString is *supposed* to always return the characters in the sequence as a String
460460
return receiver.toString();
461461
}
462-
StringBuffer result = new StringBuffer(initialBufferForReplaceWith(receiver));
462+
StringBuilder result = new StringBuilder(initialBufferForReplaceWith(receiver));
463463
do {
464464
m.appendReplacement(result, Matcher.quoteReplacement(replacementBuilder.apply(m)));
465465
} while (m.find());
@@ -477,7 +477,7 @@ public static String replaceFirst(CharSequence receiver, Pattern pattern, Functi
477477
// CharSequqence's toString is *supposed* to always return the characters in the sequence as a String
478478
return receiver.toString();
479479
}
480-
StringBuffer result = new StringBuffer(initialBufferForReplaceWith(receiver));
480+
StringBuilder result = new StringBuilder(initialBufferForReplaceWith(receiver));
481481
m.appendReplacement(result, Matcher.quoteReplacement(replacementBuilder.apply(m)));
482482
m.appendTail(result);
483483
return result.toString();

test/framework/src/main/java/org/elasticsearch/test/rest/Stash.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public Object getValue(String key) throws IOException {
9292
* modern versions of java the uncontended synchronization is very,
9393
* very cheap so that should not be a problem.
9494
*/
95-
StringBuffer result = new StringBuffer(key.length());
95+
StringBuilder result = new StringBuilder(key.length());
9696
if (false == matcher.find()) {
9797
throw new IllegalArgumentException("Doesn't contain any stash keys [" + key + "]");
9898
}
@@ -189,7 +189,7 @@ private Object getValue(List<Object> path, String key) throws IOException {
189189
}
190190
}
191191
String builtPath = Matcher.quoteReplacement(pathBuilder.toString());
192-
StringBuffer newKey = new StringBuffer(key.length());
192+
StringBuilder newKey = new StringBuilder(key.length());
193193
do {
194194
matcher.appendReplacement(newKey, builtPath);
195195
} while (matcher.find());

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/BCrypt.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ public class BCrypt {
13371337
*/
13381338
private static String encode_base64(byte d[], int len) throws IllegalArgumentException {
13391339
int off = 0;
1340-
StringBuffer rs = new StringBuffer();
1340+
StringBuilder rs = new StringBuilder();
13411341
int c1, c2;
13421342

13431343
if (len <= 0 || len > d.length) throw new IllegalArgumentException("Invalid len");
@@ -1387,7 +1387,7 @@ private static byte char64(char x) {
13871387
* @throws IllegalArgumentException if maxolen is invalid
13881388
*/
13891389
private static byte[] decode_base64(String s, int maxolen) throws IllegalArgumentException {
1390-
StringBuffer rs = new StringBuffer();
1390+
StringBuilder rs = new StringBuilder();
13911391
int off = 0, slen = s.length(), olen = 0;
13921392
byte ret[];
13931393
byte c1, c2, c3, c4, o;
@@ -1599,7 +1599,7 @@ public static String hashpw(SecureString password, String salt) {
15991599
byte passwordb[], saltb[], hashed[];
16001600
char minor = (char) 0;
16011601
int rounds, off = 0;
1602-
StringBuffer rs = new StringBuffer();
1602+
StringBuilder rs = new StringBuilder();
16031603

16041604
if (salt.charAt(0) != '$' || salt.charAt(1) != '2') throw new IllegalArgumentException("Invalid salt version");
16051605
if (salt.charAt(2) == '$') off = 3;
@@ -1674,7 +1674,7 @@ static boolean valid_minor(char minor) {
16741674
* @return an encoded salt value
16751675
*/
16761676
public static String gensalt(int log_rounds, SecureRandom random) {
1677-
StringBuffer rs = new StringBuffer();
1677+
StringBuilder rs = new StringBuilder();
16781678
byte rnd[] = new byte[BCRYPT_SALT_LEN];
16791679

16801680
random.nextBytes(rnd);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/RequestXContent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void addField(String key, Object value) {
5454
}
5555

5656
String fields() {
57-
StringBuffer s = new StringBuffer();
57+
StringBuilder s = new StringBuilder();
5858
for (Map.Entry<?, ?> entry : fields.entrySet()) {
5959
if (s.length() > 0) {
6060
s.append(", ");

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/formatter/TextFormatTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public void testCsvFormatWithCustomDelimiterRegularData() {
161161
List<String> expectedTerms = terms.stream()
162162
.map(x -> x.contains(String.valueOf(delim)) ? '"' + x + '"' : x)
163163
.collect(Collectors.toList());
164-
StringBuffer sb = new StringBuffer();
164+
StringBuilder sb = new StringBuilder();
165165
do {
166166
sb.append(expectedTerms.remove(0));
167167
sb.append(delim);

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/ActiveDirectorySIDUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static String convertToString(byte[] bytes) {
5151
}
5252

5353
char[] hex = Hex.encodeHex(bytes);
54-
StringBuffer sb = new StringBuffer();
54+
StringBuilder sb = new StringBuilder();
5555

5656
// start with 'S'
5757
sb.append('S');
@@ -76,7 +76,7 @@ public static String convertToString(byte[] bytes) {
7676

7777
// sub-authorities, little-endian
7878
for (int i = 0; i < count; i++) {
79-
StringBuffer rid = new StringBuffer();
79+
StringBuilder rid = new StringBuilder();
8080

8181
for (int k = 3; k >= 0; k--) {
8282
rid.append(hex[16 + (i * 8) + (k * 2)]);

x-pack/plugin/sql/sql-client/src/main/java/org/elasticsearch/xpack/sql/client/StringUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public static String repeatString(String in, int count) {
305305
if (count < 0) {
306306
throw new IllegalArgumentException("negative count: " + count);
307307
}
308-
StringBuffer sb = new StringBuffer(in.length() * count);
308+
StringBuilder sb = new StringBuilder(in.length() * count);
309309
for (int i = 0; i < count; i++) {
310310
sb.append(in);
311311
}

x-pack/plugin/sql/sql-client/src/test/java/org/elasticsearch/xpack/sql/client/VersionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void testInvalidVersion() {
3535
private static final String JAR_PATH_SEPARATOR = "!/";
3636

3737
private static String versionString(byte[] parts) {
38-
StringBuffer version = new StringBuffer();
38+
StringBuilder version = new StringBuilder();
3939
for (byte part : parts) {
4040
version.append(".");
4141
version.append(part);

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/plugin/TextFormatTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void testCsvFormatWithCustomDelimiterRegularData() {
9797
List<String> expectedTerms = terms.stream()
9898
.map(x -> x.contains(String.valueOf(delim)) ? '"' + x + '"' : x)
9999
.collect(Collectors.toList());
100-
StringBuffer sb = new StringBuffer();
100+
StringBuilder sb = new StringBuilder();
101101
do {
102102
sb.append(expectedTerms.remove(0));
103103
sb.append(delim);

0 commit comments

Comments
 (0)