Skip to content

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

Merged
rzo1 merged 1 commit into
masterfrom
OPENJPA-2983
Sep 2, 2026
Merged

[OPENJPA-2983] Resolve EXTRACT temporal fields by constant, not by name#166
rzo1 merged 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
@rzo1
rzo1 requested a review from solomax August 31, 2026 19:26

@solomax solomax left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do remember I have approved this one already :)

@rzo1
rzo1 merged commit 695fd67 into master Sep 2, 2026
4 checks passed
@rzo1
rzo1 deleted the OPENJPA-2983 branch September 2, 2026 17:16
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.

3 participants