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

Bug 531381

Summary: Add cleanup for redundant string operations
Product: [Eclipse Project] JDT Reporter: Karsten Thoms <karsten.thoms>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: enhancement    
Priority: P3 CC: carsten.hammer, Lars.Vogel
Version: 4.8   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard:

Description Karsten Thoms CLA 2018-02-20 06:25:03 EST
The following code contains several examples for redundant string operations. They should be removable by a cleanup operation. Additionally an "Unnecessary code" warning could be raised and quick fix provided.


public class RedundantStringOperations {
  private static final String FOO = "Foo";
  
  public static void main(String[] args) {
    System.out.println(FOO.toString()); // toString on String is redundant
    System.out.println(FOO.intern());   // intern on a constant is redundant
    
    StringBuilder sb = new StringBuilder(""); // empty string param is superfluous
    sb.append("");                            // statement is a noop
    System.out.print("");                     // statement is a noop
  }
}
Comment 1 Lars Vogel CLA 2018-06-22 05:24:58 EDT
+1, Karsten are you planning to provide a Gerrit?
Comment 2 Karsten Thoms CLA 2018-06-22 06:52:44 EDT
Not sure yet, but I'm interested. If someone picks this up earlier leave a note here.
Comment 3 Carsten Hammer CLA 2021-01-14 12:07:19 EST
Parts of it is solved in Bug 568472 in the meantime
Comment 4 Lars Vogel CLA 2021-01-28 15:25:44 EST

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