Author: bayard
Date: Wed Jan 22 08:19:22 2014
New Revision: 1560275
URL: http://svn.apache.org/r1560275
Log:
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
Modified:
commons/proper/lang/trunk/src/changes/changes.xml
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
Modified: commons/proper/lang/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1560275&r1=1560274&r2=1560275&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/changes/changes.xml [utf-8] (original)
+++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Wed Jan 22
08:19:22 2014
@@ -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>
Modified:
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java?rev=1560275&r1=1560274&r2=1560275&view=diff
==============================================================================
---
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
(original)
+++
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
Wed Jan 22 08:19:22 2014
@@ -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) {
Modified:
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java?rev=1560275&r1=1560274&r2=1560275&view=diff
==============================================================================
---
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
(original)
+++
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
Wed Jan 22 08:19:22 2014
@@ -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")