Skip to content

fix(java): reject unparseable dates with the legacy date-time provider - #3554

Open
EloB wants to merge 2 commits into
glideapps:masterfrom
EloB:fix/java-legacy-unparseable-dates
Open

EloB wants to merge 2 commits into
glideapps:masterfrom
EloB:fix/java-legacy-unparseable-dates

Conversation

@EloB

@EloB EloB commented Nov 15, 2026

Copy link
Copy Markdown

Description

With --datetime-provider legacy, the generated
Converter.parseAllDateTimeString now throws
IllegalArgumentException("Unparseable date: " + str) when no format
matches, instead of returning null. This is the one-line change in
JavaLegacyDateTimeProvider (DateTimeProvider.ts).

A second commit adds a quick-test entry to JavaLanguage,
["optional-date-time.schema", { "datetime-provider": "legacy" }], so the
schema-java fixture that CI runs also runs this schema with the legacy
provider, including its expected-failure sample. Before this, only
schema-java-datetime-legacy ran it, and CI does not run that fixture.

Related Issue

Fixes #3549

Motivation and Context

An invalid date, time or date-time value was read as null, so
optional-date-time.1.fail.date-time.json round-tripped with
"required-date-time":null instead of failing. The java8 provider's
parsers throw, and this makes the legacy provider do the same.

Previous Behaviour / Output

    return null;
}

schema-java-datetime-legacy on optional-date-time.schema:

Expected failure on input test/inputs/schema/optional-date-time.1.fail.date-time.json

(exit status 0, with "required-date-time":null in the output).

New Behaviour / Output

    throw new IllegalArgumentException("Unparseable date: " + str);
}
Error: Unparseable date: not a valid date-time at all (through reference chain: io.quicktype.TopLevel["required-date-time"])

(exit status 1). The valid sample optional-date-time.1.json still
round-trips. Every output generated with --datetime-provider legacy
gets this line in Converter.java; nothing else changes. Union
deserializers call the parser inside an ignored try/catch, so they
behave as before.

How Has This Been Tested?

Environment: macOS 26.6 (arm64), Node 24.16.0, OpenJDK 21.0.11 and
Maven 3.10.0 with
MAVEN_ARGS="-Dmaven.compiler.source=8 -Dmaven.compiler.target=8"
(JDK 21 rejects the POM's source and target 1.6).

On this branch:

  • npm ci, npm run build, npm run lint (passes), npm run test:unit
    (54 files, 241 tests pass).
  • QUICKTEST=true FIXTURE=java,schema-java npm run test:fixtures: all 145
    runs pass (one input is skipped), including the new legacy entry.
  • QUICKTEST=true FIXTURE=schema-java-datetime-legacy npm run test:fixtures -- test/inputs/schema/optional-date-time.schema:
    passes.

With only the test commit (the fix reverted):

  • QUICKTEST=true FIXTURE=java,schema-java npm run test:fixtures fails on
    the new entry with Expected failure on input …optional-date-time.1.fail.date-time.json.
  • On master (c39af7d), schema-java-datetime-legacy on
    optional-date-time.schema fails the same way.

Note: the quick-test entries run only when the fixture is run without
sample arguments.

Screenshots (if appropriate):

n/a


Written by Claude (an AI assistant made by Anthropic) and posted on behalf of the account owner (EloB). The reproduction, fix and tests were checked by running them as described above.

🤖 Generated with Claude Code

EloB and others added 2 commits November 15, 2026 07:48
…rovider

`schema-java-datetime-legacy` runs this schema, but CI's Java job runs
only `java,schema-java`. A quick-test entry runs it in `schema-java`
with `datetime-provider: legacy`, including the expected-failure sample
`optional-date-time.1.fail.date-time.json`, which that provider accepts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`parseAllDateTimeString` returned `null` when no format matched, so an
invalid date, time or date-time property was read as `null` instead of
being rejected (`optional-date-time.1.fail.date-time.json` was
accepted). Throw `IllegalArgumentException`, as the `java8` provider's
parsers throw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

[BUG]: Java with --datetime-provider legacy reads an unparseable date as null instead of rejecting it

1 participant