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

Infinite loop when running replaceAll on a specific String

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_152"
      Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 64bits 6.1.7601
      Linux 16.04 64bits

      A DESCRIPTION OF THE PROBLEM :
      The following piece of code will loop indefinitely :

          public static void main(String[] args){
              String oldValue = "BIO GOURMETSUn échéancier signé , Une ouverture de compte ";
              String newValue = oldValue.replaceAll("^(\\p{Z}|\\s)+", "");
              newValue = newValue.replaceAll("(\\p{Z}|\\s)+$", "");
              System.out.print("'"+newValue+"'");
          }

      If you duplicate the replaceAll to first replace \\p{Z} then \\s, it works...
      With many other base value (tested on about 1 million values), the code works fine. This specific value is problematic.


      REPRODUCIBILITY :
      This bug can be reproduced rarely.

            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: