You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Thomas BELOT (JIRA)" <ji...@apache.org> on 2012/06/09 15:47:42 UTC

[jira] [Created] (LANG-805) RandomStringUtils.random(count, 0, 0, false, false, universe, random) always throws java.lang.ArrayIndexOutOfBoundsException

Thomas BELOT created LANG-805:
---------------------------------

             Summary: 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.6, 2.5
            Reporter: Thomas BELOT
            Priority: Blocker


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 {code}char{code} array regardless of it's size.
(Besides {code}start{code} is useless here)

Fixed version would be : 
{code}ch = chars[random.nextInt(gap)%chars.length];{code}

--
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

        

[jira] [Commented] (LANG-805) RandomStringUtils.random(count, 0, 0, false, false, universe, random) always throws java.lang.ArrayIndexOutOfBoundsException

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-805?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13292356#comment-13292356 ] 

Sebb commented on LANG-805:
---------------------------

bq. (Besides start is useless here)

I don't think start is useless; it should be possible to specify a subset of the char array.
                
> 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
>   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}

--
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

        

[jira] [Updated] (LANG-805) RandomStringUtils.random(count, 0, 0, false, false, universe, random) always throws java.lang.ArrayIndexOutOfBoundsException

Posted by "Thomas BELOT (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-805?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas BELOT updated LANG-805:
------------------------------

    Description: 
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}

  was:
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}

    
> 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}

--
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

        

[jira] [Commented] (LANG-805) RandomStringUtils.random(count, 0, 0, false, false, universe, random) always throws java.lang.ArrayIndexOutOfBoundsException

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-805?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13292377#comment-13292377 ] 

Sebb commented on LANG-805:
---------------------------

The code has already been fixed.
Note that start == 0 and end == 0 is specifically allowed as a special case.
                
> 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

        

[jira] [Commented] (LANG-805) RandomStringUtils.random(count, 0, 0, false, false, universe, random) always throws java.lang.ArrayIndexOutOfBoundsException

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-805?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13292383#comment-13292383 ] 

Sebb commented on LANG-805:
---------------------------

Just to clarify: the code was only fixed today (in both lang 2.x and lang 3.x) thanks to your JIRA report.
However it was fixed (in SVN) just before your reworked fix was added.

The Maven artifact name change was necessary because lang3 is not fully binary compatible with lang2
                
> 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

        

[jira] [Updated] (LANG-805) RandomStringUtils.random(count, 0, 0, false, false, universe, random) always throws java.lang.ArrayIndexOutOfBoundsException

Posted by "Thomas BELOT (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-805?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas BELOT updated LANG-805:
------------------------------

    Description: 
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 it's size.
(Besides _start_ is useless here)

Fixed version would be : 
{code}ch = chars[random.nextInt(gap)%chars.length];{code}

  was:
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 {code}char{code} array regardless of it's size.
(Besides {code}start{code} is useless here)

Fixed version would be : 
{code}ch = chars[random.nextInt(gap)%chars.length];{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
>            Reporter: Thomas BELOT
>            Priority: Blocker
>              Labels: patch
>   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 it's size.
> (Besides _start_ is useless here)
> Fixed version would be : 
> {code}ch = chars[random.nextInt(gap)%chars.length];{code}

--
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

        

[jira] [Updated] (LANG-805) RandomStringUtils.random(count, 0, 0, false, false, universe, random) always throws java.lang.ArrayIndexOutOfBoundsException

Posted by "Thomas BELOT (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-805?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas BELOT updated LANG-805:
------------------------------

    Description: 
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

  was:
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}

    
> 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

        

[jira] [Updated] (LANG-805) RandomStringUtils.random(count, 0, 0, false, false, universe, random) always throws java.lang.ArrayIndexOutOfBoundsException

Posted by "Sebb (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-805?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb updated LANG-805:
----------------------

          Description: 
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}

  was:
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 it's size.
(Besides _start_ is useless here)

Fixed version would be : 
{code}ch = chars[random.nextInt(gap)%chars.length];{code}

    Affects Version/s: 3.1
    
> 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
>   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}

--
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

        

[jira] [Resolved] (LANG-805) RandomStringUtils.random(count, 0, 0, false, false, universe, random) always throws java.lang.ArrayIndexOutOfBoundsException

Posted by "Sebb (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-805?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb resolved LANG-805.
-----------------------

       Resolution: Fixed
    Fix Version/s: 2.7
                   3.2
    
> 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}

--
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

        

[jira] [Commented] (LANG-805) RandomStringUtils.random(count, 0, 0, false, false, universe, random) always throws java.lang.ArrayIndexOutOfBoundsException

Posted by "Thomas BELOT (JIRA)" <ji...@apache.org>.
    [ 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

        

[jira] [Commented] (LANG-805) RandomStringUtils.random(count, 0, 0, false, false, universe, random) always throws java.lang.ArrayIndexOutOfBoundsException

Posted by "Thomas BELOT (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-805?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13292379#comment-13292379 ] 

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

... crap

I'm a maven user and I'm relying on maven's version plugin to notify me of library updates.
The fact that you changed the artifact name for the new version of commons lang made me miss the new version ... At least this bug helped me correcting that.

Thanks Sebb
                
> 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

        

[jira] [Commented] (LANG-805) RandomStringUtils.random(count, 0, 0, false, false, universe, random) always throws java.lang.ArrayIndexOutOfBoundsException

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-805?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13292352#comment-13292352 ] 

Sebb commented on LANG-805:
---------------------------

Alternatively, choose end = chars.length.

In any case, the code needs to check for chars.length == 0 to avoid NPE in the modulus or IAE in random.nextInt(gap) as gap will be zero.
                
> 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
>            Reporter: Thomas BELOT
>            Priority: Blocker
>              Labels: patch
>   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 it's size.
> (Besides _start_ is useless here)
> Fixed version would be : 
> {code}ch = chars[random.nextInt(gap)%chars.length];{code}

--
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