[ 
https://issues.apache.org/jira/browse/LANG-1723?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Sheung Chi Chan updated LANG-1723:
----------------------------------
    Description: 
There is a missing check in the *_NumberUtils.getMantissa(String, Integer)_* 
method where a possible *_IndexOutOfBoundsException_* could be thrown when 
invalid *_str_* and *_stopPos_* are given.
{code:java}
private static String getMantissa(final String str, final int stopPos) {        
    final char firstChar = str.charAt(0);
    final boolean hasSign = firstChar == '-' || firstChar == '+';
    return hasSign ? str.substring(1, stopPos) : str.substring(0, stopPos); } 
{code}
When *_getMantissa("'-", 0);_* is called, the substring method throws 
{*}_IndexOutOfBoundsException_{*}. This could happen when calling the public 
{*}_NumberUtils.createNumber("'-");_{*}.

A checking can be added to the method and throw NumberFormatException when the 
number is invalid.

  was:
There is a missing check in the *_NumberUtils.getMantissa(String, Integer)_* 
method where a possible *_IndexOutOfBoundsException_* could be thrown when 
invalid *_str_* and *_stopPos_* are given.
{code:java}
private static String getMantissa(final String str, final int stopPos) {        
    final char firstChar = str.charAt(0);
    final boolean hasSign = firstChar == '-' || firstChar == '+';
    return hasSign ? str.substring(1, stopPos) : str.substring(0, stopPos); } 
{code}
When *_getMantissa("-", 0);_* is called, the substring method throws 
{*}_IndexOutOfBoundsException_{*}. This could happen when calling the public 
{*}_NumberUtils.createNumber("-");_{*}.

A checking can be added to the method and throw NumberFormatException when the 
number is invalid.


> IndexOutOfBoundsException thrown from NumberUtils.getMantissa method
> --------------------------------------------------------------------
>
>                 Key: LANG-1723
>                 URL: https://issues.apache.org/jira/browse/LANG-1723
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Sheung Chi Chan
>            Priority: Minor
>
> There is a missing check in the *_NumberUtils.getMantissa(String, Integer)_* 
> method where a possible *_IndexOutOfBoundsException_* could be thrown when 
> invalid *_str_* and *_stopPos_* are given.
> {code:java}
> private static String getMantissa(final String str, final int stopPos) {      
>   
>     final char firstChar = str.charAt(0);
>     final boolean hasSign = firstChar == '-' || firstChar == '+';
>     return hasSign ? str.substring(1, stopPos) : str.substring(0, stopPos); } 
> {code}
> When *_getMantissa("'-", 0);_* is called, the substring method throws 
> {*}_IndexOutOfBoundsException_{*}. This could happen when calling the public 
> {*}_NumberUtils.createNumber("'-");_{*}.
> A checking can be added to the method and throw NumberFormatException when 
> the number is invalid.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to