Skip to content

report over-long float and double as invalid in validateLexical - #92

Open
aizu-m wants to merge 1 commit into
apache:trunkfrom
aizu-m:float-double-overlong-validate
Open

report over-long float and double as invalid in validateLexical#92
aizu-m wants to merge 1 commit into
apache:trunkfrom
aizu-m:float-double-overlong-validate

Conversation

@aizu-m

@aizu-m aizu-m commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
java.lang.IllegalArgumentException: Number has more than 1024 characters
    at org.apache.xmlbeans.impl.util.MathUtil.parseAsFloat(MathUtil.java:126)
    at org.apache.xmlbeans.impl.values.JavaFloatHolder.validateLexical(JavaFloatHolder.java:71)
    at org.apache.xmlbeans.impl.validator.Validator.validateAtomicType(Validator.java:1125)

Found this feeding long numeric text through validate(). A float or double literal longer than the XmlOptions maxNumberOfCharsForNumbers cap (1024 by default) reaches MathUtil.parseAsFloat/parseAsDouble, which enforce the cap by throwing IllegalArgumentException. validateLexical in JavaFloatHolder and JavaDoubleHolder only catches NumberFormatException, so the exception leaves doc.validate() instead of being recorded as an XmlError.

Two observations. validate() throws rather than returning false. And a union such as <xs:union memberTypes="xs:double xs:string"/> rejects a value that is valid against xs:string, because the validator probes the double member first and the exception escapes the member loop.

NumberFormatException is a subclass of IllegalArgumentException, so widening the catch keeps every existing invalid-lexical case and folds the length cap into a reported error. Regression test drives a 1025-char float and double through validate().

try {
return XsTypeConverter.lexDouble(v, strict, maxNumberOfCharsForNumbers);
} catch (NumberFormatException e) {
} catch (IllegalArgumentException e) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should catch RuntimeException or just generally not tie to one exact exception type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants