Skip to content

Reject region IDs when deserializing ZoneOffset - #3192

Open
ZainnQureshii wants to merge 1 commit into
google:mainfrom
ZainnQureshii:fix-zoneoffset-region-id
Open

ZainnQureshii wants to merge 1 commit into
google:mainfrom
ZainnQureshii:fix-zoneoffset-region-id

Conversation

@ZainnQureshii

Copy link
Copy Markdown

Purpose

Closes #3189

A region ID such as {"id":"Europe/Paris"} inside a List<ZoneOffset> was read as a ZoneRegion, so fromJson returned and the caller only hit a ClassCastException later, when it used the element.

Description

The ZoneOffset adapter now checks the decoded zone and throws JsonSyntaxException with the JSON path of the offending element, using the same message as the existing type hierarchy check. OffsetDateTime, OffsetTime and ZonedDateTime get their offset field through this adapter too, so a region ID there now fails with JsonSyntaxException instead of a ClassCastException. Thanks to @DicksonWu654 for the reproduction and suggested fix.

I prepared this with AI assistance (Codex and Claude Code), and GitHub Copilot reviewed it before I opened the PR.

Checklist

  • New code follows the Google Java Style Guide
  • If necessary, new public API validates arguments, for example rejects null (no new public API)
  • New public API has Javadoc (no new public API)
  • If necessary, new unit tests have been added
    • Assertions in unit tests use Truth, see existing tests
    • No JUnit 3 features are used (such as extending class TestCase)
    • If this pull request fixes a bug, a new test was added for a situation which failed previously and is now fixed
  • mvn clean verify javadoc:jar passes without errors (JDK 21)

🤖 Generated with Claude Code

This branch has not been deployed

No deployments
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.

ZoneOffset read inside a collection or generic field can come back as a ZoneRegion

1 participant