Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 328354

Summary: Suggest use of StringBuilder instead of StringBuffer where appropriate
Product: [Eclipse Project] JDT Reporter: Alex Blewitt <alex.blewitt>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: enhancement    
Priority: P3 CC: daniel_megert
Version: 3.3   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Alex Blewitt CLA 2010-10-21 10:09:16 EDT
Build Identifier: 3.7

Code that is of the form:
public String foo() {
  StringBuffer buffer = new StringBuffer();
  buffer.append("stuff");
  return buffer.toString()
}

can be promoted to StringBuilder (if the compiler compliance is >= 1.5) without any loss of function. An informational/warning dialog noting the construction and destruction of a StringBuffer inside a single method (i.e. does not escape through field, inner class binding etc.) is guaranteed to be handled by a single thread and so can use the StringBuilder which doesn't have synchronized semantics.

Reproducible: Always
Comment 1 Dani Megert CLA 2010-10-22 03:10:26 EDT

*** This bug has been marked as a duplicate of bug 128020 ***