fix: handle XmlValueNotSupportedException for decimal twips in XWPFUt…#732
Open
shakeel-mushtaq wants to merge 1 commit into
Open
Conversation
…ils.floatValue()
OOXML documents generated by certain tools (e.g. LibreOffice, some Word
automation libraries) may store table grid column widths as non-integer
decimal values (e.g. w:w="3457.7537212449256"). The XML Schema type
STTwipsMeasure / STSignedTwipsMeasure / STMeasurementOrPercent are
defined as xs:union types, so XMLBeans represents such values as
XmlUnionImpl. Calling getFloatValue() on that union throws:
XmlValueNotSupportedException: Could not get a Java numeric type
from a Schema string type
This cascades up through XWPFTableUtil.getGridColList() and crashes
the entire XHTML converter with an XWPFConverterException, making
thumbnail and preview generation impossible for affected documents.
Fix:
- Wrap getFloatValue() in the three floatValue() overloads with a
try/catch that falls back to parseSafeFloat().
- parseSafeFloat() retrieves the raw string value and handles:
* Decimal twips strings (e.g. "3457.75") → parsed via Float.parseFloat()
* Percentage strings (e.g. "50%") → divided by 100
* The literal "auto" → 0.0f
* Any remaining unparseable value → 0.0f (safe fallback)
- Added null-guards on all three overloads.
Reproducer: a .docx whose word/document.xml contains
<w:gridCol w:w="3457.7537212449256"/>
will now convert successfully instead of throwing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…ils.floatValue()
OOXML documents generated by certain tools (e.g. LibreOffice, some Word automation libraries) may store table grid column widths as non-integer decimal values (e.g. w:w="3457.7537212449256"). The XML Schema type STTwipsMeasure / STSignedTwipsMeasure / STMeasurementOrPercent are defined as xs:union types, so XMLBeans represents such values as XmlUnionImpl. Calling getFloatValue() on that union throws:
XmlValueNotSupportedException: Could not get a Java numeric type
from a Schema string type
This cascades up through XWPFTableUtil.getGridColList() and crashes the entire XHTML converter with an XWPFConverterException, making thumbnail and preview generation impossible for affected documents.
Fix:
Reproducer: a .docx whose word/document.xml contains
<w:gridCol w:w="3457.7537212449256"/>
will now convert successfully instead of throwing.