Skip to content

wrap getDate() IllegalStateException in rich parser date getters#76

Open
aizu-m wants to merge 1 commit into
apache:trunkfrom
aizu-m:richparser-date-lexical-error
Open

wrap getDate() IllegalStateException in rich parser date getters#76
aizu-m wants to merge 1 commit into
apache:trunkfrom
aizu-m:richparser-date-lexical-error

Conversation

@aizu-m

@aizu-m aizu-m commented Jul 6, 2026

Copy link
Copy Markdown

Rich parser threw on an xsd:dateTime element instead of reporting a bad value:

java.lang.IllegalStateException: cannot do date math without a complete date
    at org.apache.xmlbeans.GDateBuilder.julianDateForGDate(GDateBuilder.java:1079)
    at org.apache.xmlbeans.GDateBuilder.dateForGDate(GDateBuilder.java:1099)
    at org.apache.xmlbeans.GDateBuilder.getDate(GDateBuilder.java:1073)
    at org.apache.xmlbeans.impl.richParser.XMLStreamReaderExtImpl.getDateValue(XMLStreamReaderExtImpl.java:206)

getDateValue turns the parsed GDate into a java.util.Date via GDateBuilder.getDate(). getDate() throws IllegalStateException, not IllegalArgumentException, when the value is not a complete date (a time, gYear or gYearMonth reaching the field) or its year is before the Julian epoch. The getter caught only IllegalArgumentException, so the IllegalStateException escaped.

Traced the same shape through getAttributeDateValue by index and by name. getCalendarValue is unaffected since getCalendar() only sets calendar fields, and getGDateValue returns the GDate without the Date conversion.

The other getters and the JavaGDateHolderEx validate path already surface a bad value as InvalidLexicalValueException. Widened the catch on the three getDate() sites to match, and added a test driving the time, gYear and pre-epoch cases plus the attribute overloads.

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.

1 participant