Skip to content

Commit

Permalink
Replace StringBuffer with StringBuilder where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
quaff committed Sep 3, 2020
1 parent 88249b2 commit 7e6c4da
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ public void testSunnyDayPathLogsCorrectlyWithPrettyMuchAllPlaceholdersMatching()
given(log.isTraceEnabled()).willReturn(true);

CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
interceptor.setEnterMessage(new StringBuffer()
interceptor.setEnterMessage(new StringBuilder()
.append("Entering the '").append(CustomizableTraceInterceptor.PLACEHOLDER_METHOD_NAME)
.append("' method of the [").append(CustomizableTraceInterceptor.PLACEHOLDER_TARGET_CLASS_NAME)
.append("] class with the following args (").append(CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENTS)
.append(") and arg types (").append(CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENT_TYPES)
.append(").").toString());
interceptor.setExitMessage(new StringBuffer()
interceptor.setExitMessage(new StringBuilder()
.append("Exiting the '").append(CustomizableTraceInterceptor.PLACEHOLDER_METHOD_NAME)
.append("' method of the [").append(CustomizableTraceInterceptor.PLACEHOLDER_TARGET_CLASS_SHORT_NAME)
.append("] class with the following args (").append(CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENTS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ class ReverseMethodReplacer implements MethodReplacer, Serializable {
@Override
public Object reimplement(Object obj, Method method, Object[] args) throws Throwable {
String s = (String) args[0];
return new StringBuffer(s).reverse().toString();
return new StringBuilder(s).reverse().toString();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ void replaceMethodOverrideWithSetterInjection() {

// Now test replace
String s = "this is not a palindrome";
String reverse = new StringBuffer(s).reverse().toString();
String reverse = new StringBuilder(s).reverse().toString();
assertThat(oom.replaceMe(s)).as("Should have overridden to reverse, not echo").isEqualTo(reverse);

assertThat(oom.replaceMe()).as("Should have overridden no-arg overloaded replaceMe method to return fixed value").isEqualTo(FixedMethodReplacer.VALUE);
Expand Down Expand Up @@ -1380,7 +1380,7 @@ void serializableMethodReplacerAndSuperclass() throws IOException {
reader.loadBeanDefinitions(DELEGATION_OVERRIDES_CONTEXT);
SerializableMethodReplacerCandidate s = (SerializableMethodReplacerCandidate) xbf.getBean("serializableReplacer");
String forwards = "this is forwards";
String backwards = new StringBuffer(forwards).reverse().toString();
String backwards = new StringBuilder(forwards).reverse().toString();
assertThat(s.replaceMe(forwards)).isEqualTo(backwards);
// SPR-356: lookup methods & method replacers are not serializable.
assertThat(SerializationTestUtils.isSerializable(s)).as("Lookup methods and method replacers are not meant to be serializable.").isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MessengerScrambler {

public String scramble(ProceedingJoinPoint pjp) throws Throwable {
String message = (String) pjp.proceed();
return new StringBuffer(message).reverse().toString();
return new StringBuilder(message).reverse().toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private static Class getClass(String className, ClassLoader loader, String[] pac
while ((index = className.indexOf("[]", index) + 1) > 0) {
dimensions++;
}
StringBuffer brackets = new StringBuffer(className.length() - dimensions);
StringBuilder brackets = new StringBuilder(className.length() - dimensions);
for (int i = 0; i < dimensions; i++) {
brackets.append('[');
}
Expand Down

0 comments on commit 7e6c4da

Please sign in to comment.