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

String.replaceAll() not giving expected result.

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      OS: Windows 10 Pro
      java: Java SE Development Kit 8u211 for Windows x64

      A DESCRIPTION OF THE PROBLEM :
      The replaceAll method of a String object produces unexpected results.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
                     String sourceText = "ab";
      String regex = "ab";
      String replacement = "\\\"";
      String result = sourceText.replaceAll(regex, replacement);
      if (!result.equals(replacement)) {
      throw new RuntimeException("Replacement result does not meet expectations");
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The variable 'result' is equal to the variable 'replacement'
      ACTUAL -
      The variable 'result' is not equal to the variable 'replacement'

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              psonal Pallavi Sonal (Inactive)
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: