Skip to content

[OPENJPA-2983] Resolve EXTRACT temporal fields by constant, not by name - #166

Open
rzo1 wants to merge 1 commit into
masterfrom
OPENJPA-2983
Open

[OPENJPA-2983] Resolve EXTRACT temporal fields by constant, not by name#166
rzo1 wants to merge 1 commit into
masterfrom
OPENJPA-2983

Conversation

@rzo1

@rzo1 rzo1 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

CriteriaBuilderImpl.extract() derived the DateTimeExtractField from field.toString().toUpperCase(...). Locale.ROOT on master closed the Turkish-locale hole, but the lookup still depended on the exact wording of the spec constants, and an unrecognised field failed with Enum.valueOf's "No enum constant ..." rather than anything actionable.

The LocalDateField / LocalTimeField / LocalDateTimeField constants are now mapped to their DateTimeExtractField equivalents by identity, and anything else is rejected with a meaningful message. Identity is safe: the three classes have a single private constructor, are not Serializable, and expose no factory.

No behaviour change for working queries — LocalDateTimeField.DATE/TIME already threw IllegalArgumentException (their toString() is lowercase, so valueOf never matched) and still do, with a better message.

CriteriaBuilderImpl.extract() derived the DateTimeExtractField from
field.toString().toUpperCase(), which depends on the default locale and on
the textual representation the specification constants happen to use. Map
the LocalDateField / LocalTimeField / LocalDateTimeField constants to their
DateTimeExtractField equivalents by identity instead, and reject any other
temporal field with a meaningful message instead of letting Enum.valueOf
fail.

TestExtractTemporalField pins every entry of the new mapping table, which
is where the risk now sits: it is a characterisation test of the 16 hand
written pairs, not a reproduction of the original defect, since the name
based lookup produced the same result for all constants once Locale.ROOT
was passed.
@rzo1
rzo1 requested review from cristof and solomax August 29, 2026 17:37
@rzo1 rzo1 self-assigned this Aug 29, 2026
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