You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2023/12/09 14:34:00 UTC
[jira] [Resolved] (LANG-1723) Throw NumberFormatException instead of IndexOutOfBoundsException in NumberUtils.getMantissa(String, int)
[ https://issues.apache.org/jira/browse/LANG-1723?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary D. Gregory resolved LANG-1723.
-----------------------------------
Fix Version/s: 3.14.1
Resolution: Fixed
> Throw NumberFormatException instead of IndexOutOfBoundsException in NumberUtils.getMantissa(String, int)
> --------------------------------------------------------------------------------------------------------
>
> Key: LANG-1723
> URL: https://issues.apache.org/jira/browse/LANG-1723
> Project: Commons Lang
> Issue Type: Bug
> Reporter: Sheung Chi Chan
> Priority: Minor
> Fix For: 3.14.1
>
>
> 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)