Author: fanningpj
Date: Sat Jun 13 11:09:00 2026
New Revision: 1935231
Log:
no need to wait till exception is thrown to handle inf/nan
Modified:
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/XsTypeConverter.java
Modified:
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/XsTypeConverter.java
==============================================================================
---
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/XsTypeConverter.java
Sat Jun 13 11:08:43 2026 (r1935230)
+++
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/XsTypeConverter.java
Sat Jun 13 11:09:00 2026 (r1935231)
@@ -43,30 +43,25 @@ public final class XsTypeConverter {
public static float lexFloat(CharSequence cs)
throws NumberFormatException {
final String v = cs.toString();
- try {
- //current jdk impl of parseFloat calls trim() on the string.
- //Any other space is illegal anyway, whether there are one or more
spaces.
- //so no need to do a collapse pass through the string.
- if (cs.length() > 1) {
- char ch = cs.charAt(cs.length() - 1);
- if ((ch == 'f' || ch == 'F') && cs.charAt(cs.length() - 2) !=
'N') {
- throw new NumberFormatException("Invalid char '" + ch + "'
in float.");
- }
- }
- return Float.parseFloat(v);
- } catch (NumberFormatException e) {
- if (v.equals(POS_INF_LEX)) {
- return Float.POSITIVE_INFINITY;
- }
- if (v.equals(NEG_INF_LEX)) {
- return Float.NEGATIVE_INFINITY;
- }
- if (v.equals(NAN_LEX)) {
- return Float.NaN;
+ if (v.equals(POS_INF_LEX)) {
+ return Float.POSITIVE_INFINITY;
+ }
+ if (v.equals(NEG_INF_LEX)) {
+ return Float.NEGATIVE_INFINITY;
+ }
+ if (v.equals(NAN_LEX)) {
+ return Float.NaN;
+ }
+ //current jdk impl of parseFloat calls trim() on the string.
+ //Any other space is illegal anyway, whether there are one or more
spaces.
+ //so no need to do a collapse pass through the string.
+ if (cs.length() > 1) {
+ char ch = cs.charAt(cs.length() - 1);
+ if ((ch == 'f' || ch == 'F') && cs.charAt(cs.length() - 2) != 'N')
{
+ throw new NumberFormatException("Invalid char '" + ch + "' in
float.");
}
-
- throw e;
}
+ return Float.parseFloat(v);
}
public static float lexFloat(CharSequence cs, Collection<XmlError> errors)
{
@@ -97,31 +92,25 @@ public final class XsTypeConverter {
public static double lexDouble(CharSequence cs)
throws NumberFormatException {
final String v = cs.toString();
-
- try {
- //current jdk impl of parseDouble calls trim() on the string.
- //Any other space is illegal anyway, whether there are one or more
spaces.
- //so no need to do a collapse pass through the string.
- if (cs.length() > 0) {
- char ch = cs.charAt(cs.length() - 1);
- if (ch == 'd' || ch == 'D') {
- throw new NumberFormatException("Invalid char '" + ch + "'
in double.");
- }
- }
- return Double.parseDouble(v);
- } catch (NumberFormatException e) {
- if (v.equals(POS_INF_LEX)) {
- return Double.POSITIVE_INFINITY;
- }
- if (v.equals(NEG_INF_LEX)) {
- return Double.NEGATIVE_INFINITY;
- }
- if (v.equals(NAN_LEX)) {
- return Double.NaN;
+ if (v.equals(POS_INF_LEX)) {
+ return Double.POSITIVE_INFINITY;
+ }
+ if (v.equals(NEG_INF_LEX)) {
+ return Double.NEGATIVE_INFINITY;
+ }
+ if (v.equals(NAN_LEX)) {
+ return Double.NaN;
+ }
+ //current jdk impl of parseDouble calls trim() on the string.
+ //Any other space is illegal anyway, whether there are one or more
spaces.
+ //so no need to do a collapse pass through the string.
+ if (cs.length() > 0) {
+ char ch = cs.charAt(cs.length() - 1);
+ if (ch == 'd' || ch == 'D') {
+ throw new NumberFormatException("Invalid char '" + ch + "' in
double.");
}
-
- throw e;
}
+ return Double.parseDouble(v);
}
public static double lexDouble(CharSequence cs, Collection<XmlError>
errors) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]