LANG-807 RandomStringUtils throws confusing IAE when end <= start
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1348583 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
27bcbcc728
commit
4a65cb8da2
|
@ -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 <= 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>
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -130,6 +130,17 @@ public class RandomStringUtilsTest extends junit.framework.TestCase {
|
|||
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 {
|
||||
|
|
Loading…
Reference in New Issue