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

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

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 6
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b14
    • CPU:
      generic
    • OS:
      generic

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: