commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 14883] New: - StringUtils.countMatches loops forever if substring empty
Date Wed, 27 Nov 2002 07:06:17 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14883>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14883

StringUtils.countMatches loops forever if substring empty

           Summary: StringUtils.countMatches loops forever if substring
                    empty
           Product: Commons
           Version: 1.0.1 Final
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Lang
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: tackline@tackline.demon.co.uk


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;
        }

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message