Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5027748

Avoid invoking dubious String(String) constructor in Pattern.java

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 5.0
    • core-libs
    • b14
    • generic
    • generic

      David Hovemeyer's and Bill Pugh's "findbugs" program have found some bugs in
      Pattern.java. David writes:

      M Dm: java.util.regex.Pattern.normalizeCharClass(StringBuffer,int) invokes dubious new String(String) constructor; just use
       the argument At Pattern.java:[line 1211]

              if (eq != null) {
                  result = new String("(?:"+charClass.toString()+
                                      eq.toString()+")");
              } else {
                  result = charClass.toString();
              }

      Just slow and embarrassing. Should be:


              if (eq != null) {
                  result = "(?:"+charClass.toString()+
                                      eq.toString()+")";
              } else {
                  result = charClass.toString();
              }

      ----

      M Dm: java.util.regex.Pattern.produceEquivalentAlternation(String) invokes dubious new String(String) constructor; just use
       the argument At Pattern.java:[line 1230]

          private String produceEquivalentAlternation(String source) {
              int len = countChars(source, 0, 1);
              if (source.length() == len)
                  // source has one character.
                  return new String(source); // should be return source;

      ditto.

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: