You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Sheung Chi Chan (Jira)" <ji...@apache.org> on 2023/12/08 14:52:00 UTC

[jira] [Updated] (LANG-1723) IndexOutOfBoundsException thrown from NumberUtils.getMantissa method

     [ 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 other method in MethodUtils calls {*}_getMantissa("{-}", 0);{-}_{*}, 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.

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

} 

When other method in MethodUtils calls {*}_getMantissa("-", 0);_{*}, 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 other method in MethodUtils calls {*}_getMantissa("{-}", 0);{-}_{*}, 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)