[ 
https://issues.apache.org/jira/browse/LANG-805?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13292362#comment-13292362
 ] 

Thomas BELOT commented on LANG-805:
-----------------------------------

You're right in both comments and I was wrong in my analysis (thanks for 
pointing that out).
I've reworked a fix which adds IAE in error cases : 
{code}
                if (start < 0)
                        throw new IllegalArgumentException(
                                        "Requested start parameter is 
negative");
                if (end < 0)
                        throw new IllegalArgumentException(
                                        "Requested end parameter is negative");
                if ((start == 0) && (end == 0)) {
                        if (chars != null) {
                                throw new IllegalArgumentException(
                                                "Requested end parameter is 0 
(should be positive)");
                        } else if (!letters && !numbers) {
                                start = 0;
                                end = Integer.MAX_VALUE;
                        } else {
                                end = 'z' + 1;
                                start = ' ';
                        }
                }
                if (chars != null && end > chars.length)
                        throw new IllegalArgumentException(
                                        "Requested end parameter is greater 
than chars.length");

                char[] buffer = new char[count];
                int gap = end - start;
                if (gap <= 0) {
                        throw new IllegalArgumentException(
                                        "Requested gap (=end - start) is 
negative or zero");
                }
{code}
                
> RandomStringUtils.random(count, 0, 0, false, false, universe, random) always 
> throws java.lang.ArrayIndexOutOfBoundsException
> ----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: LANG-805
>                 URL: https://issues.apache.org/jira/browse/LANG-805
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.5, 2.6, 3.1
>            Reporter: Thomas BELOT
>            Priority: Blocker
>              Labels: patch
>             Fix For: 3.2, 2.7
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> In commons-lang 2.6 line 250 :
> {code}ch = chars[random.nextInt(gap) + start];{code}
> -This line of code takes a random int to fetch a char in the _chars_ array 
> regardless of its size.-
> -(Besides _start_ is useless here)-
> -Fixed version would be :-
> {code}//ch = chars[random.nextInt(gap)%chars.length];{code}
> When user pass 0 as _end_ or when the array is not null but empty this line 
> ends up with an exception

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to