Class UseStringBufferLengthRule

  • All Implemented Interfaces:
    JavaParserVisitor, ImmutableLanguage, PropertySource, Rule

    public class UseStringBufferLengthRule
    extends AbstractJavaRule
    This rule finds places where StringBuffer.toString() is called just to see if the string is 0 length by either using .equals("") or toString().length().
     StringBuffer sb = new StringBuffer("some string");
     if (sb.toString().equals("")) {
         // this is wrong
     }
     if (sb.length() == 0) {
         // this is right
     }
     
    Author:
    acaplan, Philip Graf