Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-56

StringUtils.countMatches loops forever if substring empty

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0
    • 2.0
    • lang.*
    • None
    • Operating System: Linux
      Platform: PC

    • 14883

    Description

      If you do say StringUtils.countMatches("x", ""), then it goes into an infinite loop.

      Also sub isn't checked for null if str is null also. For instance
      StringUtils.countMatches(null, null) should throw an NPE instead of 0.

      To fix both problems put the following code at the start of the method:

      if (sub.equals(""))

      { return 0; }

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            tackline@tackline.demon.co.uk Thomas Hawtin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment