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

StringUtils.getLevenshteinDistance with too big of a threshold returns wrong result

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.1
    • 3.3
    • lang.*
    • None

    Description

      StringUtils.getLevenshteinDistance(CharSequence s, CharSequence t, int threshold) specifies:

      Find the Levenshtein distance between two Strings if it's less than or equal to a given threshold.

      When passing a threshold > Integer.MAX_VALUE - max(s.length(), t.length()) the method always returns -1.
      The simplest use case is passing Integer.MAX_VALUE (a common practice if one would want to find the min/max LD of a string to several other strings in an iterative fashion.

      The code should be fixed to consider the threshold in relation to the source/target lengths, or alternatively the javadoc should be fixed to pronounce the current limit.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              kunda Yaniv Kunda
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: