Author: sebb
Date: Wed Mar 27 16:29:25 2013
New Revision: 1461697
URL: http://svn.apache.org/r1461697
Log:
Document why double exponent (e and E) seems to work even though the index will
be wrong
Modified:
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
Modified:
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java?rev=1461697&r1=1461696&r2=1461697&view=diff
==============================================================================
---
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
(original)
+++
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
Wed Mar 27 16:29:25 2013
@@ -478,12 +478,14 @@ public class NumberUtils {
String dec;
String exp;
final int decPos = str.indexOf('.');
- final int expPos = str.indexOf('e') + str.indexOf('E') + 1; // TODO
assumes both not present
+ final int expPos = str.indexOf('e') + str.indexOf('E') + 1; // assumes
both not present
+ // if both e and E are present, this is caught by the checks on expPos
(which prevent IOOBE)
+ // and the parsing which will detect if e or E appear in a number due
to using the wrong offset
if (decPos > -1) { // there is a decimal point
if (expPos > -1) { // there is an exponent
- if (expPos < decPos || expPos > str.length()) {
+ if (expPos < decPos || expPos > str.length()) { // prevents
double exponent causing IOOBE
throw new NumberFormatException(str + " is not a valid
number.");
}
dec = str.substring(decPos + 1, expPos);
@@ -493,7 +495,7 @@ public class NumberUtils {
mant = str.substring(0, decPos);
} else {
if (expPos > -1) {
- if (expPos > str.length()) {
+ if (expPos > str.length()) { // prevents double exponent
causing IOOBE
throw new NumberFormatException(str + " is not a valid
number.");
}
mant = str.substring(0, expPos);