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

REGRESSION: Regex: replacing '$' i.e. EOL fails

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      rc
    • CPU:
      x86
    • OS:
      windows_98, windows_2000
    • Verification:
      Verified

      Backports

        Description



        Name: nt126004 Date: 07/08/2002


        FULL PRODUCT VERSION :
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b14)
        Java HotSpot(TM) Client VM (build 1.4.1-beta-b14, mixed mode)

        FULL OPERATING SYSTEM VERSION :

        Microsoft Windows 2000 [Version 5.00.2195]

        ADDITIONAL OPERATING SYSTEMS :

        N/A

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        Nothing special, pure java.util.regex issue.

        Problem occurs with both client and server VMs.

        A DESCRIPTION OF THE PROBLEM :
        Using Pattern and Matcher in java.util.regex to replace CR
        (regex '$') with some other String, Java 1.4.0 works fine
        but 1.4.1 beta matches on almost every character, rather
        than just end-of-line chars.

        REGRESSION. Last worked in version 1.4

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Run the example code with Java 1.4.0_01 and Java 1.4.1
        beta
        2. Compare actual and expected output.


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        With 1.4.0_01 I get (good):

        was: first bit
        second bit
        is : first bitCRsecond bitCR

        With 1.4.1 beta I get (bad):

        was: first bit
        second bit
        is : CRfCRiCRrCRsCRtCR CRbCRiCRtCR
        CRsCReCRcCRoCRnCRdCR CRbitCR


        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        No exceptions or errors, just incorrect output.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.util.regex.*;

        public class DollarTest {

        public static void main(String[] args) {

        Pattern findCR = Pattern.compile("$", Pattern.MULTILINE);

        String testString = "first bit\nsecond bit";

        Matcher matcher = findCR.matcher(testString);
        String output = matcher.replaceAll("CR"); // I do mean the String "CR"

        System.out.println("was: "+testString);
        System.out.println("is : "+output);
        }
        }

        ---------- END SOURCE ----------

        CUSTOMER WORKAROUND :
        Not worked out one yet, will stick to Java 1.4.0_01 for the
        moment.

        Release Regression From : 1.4.0_01
        The above release value was the last known release where this
        bug was known to work. Since then there has been a regression.

        (Review ID: 158892)
        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                mmcclosksunw Michael Mccloskey (Inactive)
                Reporter:
                nthompsosunw Nathanael Thompson (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: