commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1348583 - in /commons/proper/lang/trunk/src: changes/changes.xml main/java/org/apache/commons/lang3/RandomStringUtils.java test/java/org/apache/commons/lang3/RandomStringUtilsTest.java
Date Sun, 10 Jun 2012 12:40:48 GMT
Author: sebb
Date: Sun Jun 10 12:40:48 2012
New Revision: 1348583

URL: http://svn.apache.org/viewvc?rev=1348583&view=rev
Log:
LANG-807 RandomStringUtils throws confusing IAE when end <= start

Modified:
    commons/proper/lang/trunk/src/changes/changes.xml
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/RandomStringUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.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=1348583&r1=1348582&r2=1348583&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/changes/changes.xml (original)
+++ commons/proper/lang/trunk/src/changes/changes.xml Sun Jun 10 12:40:48 2012
@@ -22,6 +22,7 @@
   <body>
 
   <release version="3.2" date="TBA" description="Next release">
+    <action issue="LANG-807" type="fix">RandomStringUtils throws confusing IAE when
end &lt;= start</action>
     <action issue="LANG-805" type="fix">RandomStringUtils.random(count, 0, 0, false,
false, universe, random) always throws java.lang.ArrayIndexOutOfBoundsException</action>
     <action issue="LANG-802" type="fix">LocaleUtils - unnecessary recursive call in
SyncAvoid class.</action>
     <action issue="LANG-800" type="fix">Javadoc bug in DateUtils#ceiling for Calendar
and Object versions.</action>

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/RandomStringUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/RandomStringUtils.java?rev=1348583&r1=1348582&r2=1348583&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/RandomStringUtils.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/RandomStringUtils.java
Sun Jun 10 12:40:48 2012
@@ -242,6 +242,10 @@ public class RandomStringUtils {
                     start = ' ';                
                 }
             }
+        } else {
+            if (end <= start) {
+                throw new IllegalArgumentException("Parameter end (" + end + ") must be greater
than start (" + start + ")");
+            }
         }
 
         char[] buffer = new char[count];

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java?rev=1348583&r1=1348582&r2=1348583&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java
Sun Jun 10 12:40:48 2012
@@ -130,6 +130,17 @@ public class RandomStringUtilsTest exten
         assertEquals("aaa", RandomStringUtils.random(3,0,0,false,false,new char[]{'a'},new
Random(seed)));
     }
 
+    public void testLANG807() {
+        try {
+            RandomStringUtils.random(3,5,5,false,false);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException ex) { // distinguish from Random#nextInt message
+            final String msg = ex.getMessage();
+            assertTrue("Message (" + msg + ") must contain 'start'", msg.contains("start"));
+            assertTrue("Message (" + msg + ") must contain 'end'", msg.contains("end"));
+        }
+    }
+
     public void testExceptions() {
         final char[] DUMMY = new char[]{'a'}; // valid char array
         try {



Mime
View raw message