named-regexp
  1. named-regexp
  2. REGEX-9

Android: NamedPattern.compile() gets stuck in infinite loop

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.1.9
    • Labels:
      None
    • Environment:

      Android 4.2 (SDK 17) Simulator (other Android versions likely affected)

      Description

      In Android, the NamedPattern.compile() function gets caught in an infinite loop in buildStandardPattern(), trying to find named capture groups in the given pattern.

      This does not occur outside of Android Java (in desktop platforms of J2SE).

        Activity

        Hide
        Anthony Trinh [Administrator] added a comment - - edited

        Matcher.reset() in Android does not reload the string input and continues using the original value. A while-loop in NamedPattern.buildStandardPattern() checks whether there are any remaining named capture groups that need to be converted into unnamed capture groups. On each iteration, it calls Matcher.reset() (without arguments) to reload the newly updated string in the matcher, but the reload was not occurring in Android, thus the Matcher was finding the search target in the original string and repeating itself. This change passes the updated string as an argument to Matcher.reset(String), which correctly updates the matcher's string input (the same as the desktop version of it).

        Show
        Anthony Trinh [Administrator] added a comment - - edited Matcher.reset() in Android does not reload the string input and continues using the original value. A while -loop in NamedPattern.buildStandardPattern() checks whether there are any remaining named capture groups that need to be converted into unnamed capture groups. On each iteration, it calls Matcher.reset() (without arguments) to reload the newly updated string in the matcher, but the reload was not occurring in Android, thus the Matcher was finding the search target in the original string and repeating itself. This change passes the updated string as an argument to Matcher.reset(String) , which correctly updates the matcher's string input (the same as the desktop version of it).

          People

          • Assignee:
            Anthony Trinh [Administrator]
            Reporter:
            Anthony Trinh [Administrator]
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - Not Specified
              Not Specified
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 1 hour
              1h

                Development