Applying Eli Lindsey's patch to Yaniv Kunda's report in LANG-936 that StringUtils.getLevensteinDistance(String, String, int) gave the wrong answer when the int threshold is near Integer.MAX_VALUE

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1560275 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2014-01-22 08:19:22 +00:00
parent 3a8595f1a5
commit 8cd2339a97
3 changed files with 10 additions and 1 deletions

View File

@ -22,6 +22,7 @@
<body>
<release version="3.3" date="TBA" description="Bugfix and Feature release">
<action issue="LANG-936" type="fix" dev="bayard" due-to="Yaniv Kunda, Eli Lindsey">StringUtils.getLevenshteinDistance with too big of a threshold returns wrong result</action>
<action issue="LANG-943" type="fix" dev="kinow">Test DurationFormatUtilsTest.testEdgeDuration fails in JDK 1.6, 1.7 and 1.8, BRST time zone</action>
<action issue="LANG-613" type="fix" dev="mbenson">ConstructorUtils.getAccessibleConstructor() Does Not Check the Accessibility of Enclosing Classes</action>
<action issue="LANG-951" type="fix" dev="britter" due-to="Sebastian Götz">Fragments are wrong by 1 day when using fragment YEAR or MONTH</action>

View File

@ -6938,7 +6938,7 @@ public class StringUtils {
// compute stripe indices, constrain to array size
final int min = Math.max(1, j - threshold);
final int max = Math.min(n, j + threshold);
final int max = (j > Integer.MAX_VALUE - threshold) ? n : Math.min(n, j + threshold);
// the stripe may lead off of the table if s and t are of different sizes
if (min > max) {

View File

@ -1974,6 +1974,14 @@ public class StringUtilsTest {
assertEquals(8, StringUtils.getLevenshteinDistance("zzzzzzzz", "hippo",8) );
assertEquals(1, StringUtils.getLevenshteinDistance("hello", "hallo",1) );
assertEquals(1, StringUtils.getLevenshteinDistance("frog", "fog", Integer.MAX_VALUE) );
assertEquals(3, StringUtils.getLevenshteinDistance("fly", "ant", Integer.MAX_VALUE) );
assertEquals(7, StringUtils.getLevenshteinDistance("elephant", "hippo", Integer.MAX_VALUE) );
assertEquals(7, StringUtils.getLevenshteinDistance("hippo", "elephant", Integer.MAX_VALUE) );
assertEquals(8, StringUtils.getLevenshteinDistance("hippo", "zzzzzzzz", Integer.MAX_VALUE) );
assertEquals(8, StringUtils.getLevenshteinDistance("zzzzzzzz", "hippo", Integer.MAX_VALUE) );
assertEquals(1, StringUtils.getLevenshteinDistance("hello", "hallo", Integer.MAX_VALUE) );
// exceptions
try {
@SuppressWarnings("unused")