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

Matcher does not terminate, or is extremly slow

XMLWordPrintable

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


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.10586]

      A DESCRIPTION OF THE PROBLEM :
      The simple pattern "^(([\\w\\-_]*)\\:?([\\w\\-_]*))*$" applied to "hubManagementFilter:hubTablePanelExpansion:0.0:_t25" does not seem to terminate, or takes extremely long.

      The pattern does not seem too extreme. And I run into a problem when using it with JSF iceFaces.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just run this program:

      public static void main(String[] args) {

      long start = System.currentTimeMillis();

      Pattern p = Pattern.compile("^(([\\w\\-_]*)\\:?([\\w\\-_]*))*$");

      Matcher m = p.matcher("hubManagementFilter:hubTablePanelExpansion:0.0:_t25");

      boolean matches = m.matches();

      long end = System.currentTimeMillis();

      System.out.println("String matches: " + matches + " in " + (end-start) + " millis");
      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Termination in a reasonable time.
      ACTUAL -
      Not terminating

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package at.arctis.javatests;

      import java.util.regex.Matcher;
      import java.util.regex.Pattern;

      public class PatternTests {

      public static void main(String[] args) {

      long start = System.currentTimeMillis();

      Pattern p = Pattern.compile("^(([\\w\\-_]*)\\:?([\\w\\-_]*))*$");

      Matcher m = p.matcher("hubManagementFilter:hubTablePanelExpansion:0.0:_t25");

      boolean matches = m.matches();

      long end = System.currentTimeMillis();

      System.out.println("String matches: " + matches + " in " + (end-start) + " millis");
      }

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Choose shorter identifiers in JSF-Application

            sherman Xueming Shen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: