Skip to content

fix(wait-task): accept ISO-8601 duration and fix misleading error message - #1474

Open
shaileshpadave wants to merge 3 commits into
mainfrom
fix/issue-1310-wait-duration-error-message
Open

fix(wait-task): accept ISO-8601 duration and fix misleading error message#1474
shaileshpadave wants to merge 3 commits into
mainfrom
fix/issue-1310-wait-duration-error-message

Conversation

@shaileshpadave

Copy link
Copy Markdown
Contributor

What

A WAIT task with "duration": "PT1S" (ISO-8601) failed with "Either date or duration is passed as null" — a message that implies the field was absent, when it was actually present but in an unsupported format.

Two changes:

  1. DateTimeUtils.parseDuration() — after the custom format ("1s", "2m") fails to match, fall back to java.time.Duration.parse() so ISO-8601 durations like "PT1S", "P5D", "PT1H30M" work natively.

  2. WorkflowTaskTypeConstraint — when parseDuration() still throws (genuinely invalid input), surface the actual error message instead of the misleading "passed as null" message.

Fixes #1310

How to verify

  1. Define a workflow with a WAIT task using ISO-8601 duration:
    { "type": "WAIT", "name": "wait1", "taskReferenceName": "wait_ref",
      "inputParameters": { "duration": "PT1S" } }
  2. Before fix: task fails immediately with "Either date or duration is passed as null".
  3. After fix: task waits 1 second and completes normally.
  4. To test the error message fix: use an invalid value like "duration": "PT" — the error now reads "Not valid duration: PT" instead of blaming null.

…nvalid format

parseDuration() only accepted the custom "1s"/"2m"/"1h 30m" format. Using
ISO-8601 (e.g. "PT1S") threw an IllegalArgumentException that got caught and
re-thrown with the misleading "Either date or duration is passed as null" message.

Now parseDuration() tries the custom format first, then falls back to
Duration.parse() for ISO-8601. If both fail, the constraint surfaces the actual
error message from parseDuration() instead of the null-blame message.

Fixes #1310
@v1r3n
v1r3n requested a review from mp-orkes August 4, 2026 20:52
return Duration.parse(text);
} catch (java.time.format.DateTimeParseException e) {
throw new IllegalArgumentException("Not valid duration: " + text);
}

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.

Context

This looks good. Accepting ISO 8601 durations through the Duration.parse fallback is clean, the regex and ISO paths do not overlap, and the new error message is a real improvement over the old date or duration is null wording. I also checked the message change at WorkflowTaskTypeConstraint.java:333 that passes e.getMessage() with the user text into buildConstraintViolationWithTemplate, and on Hibernate Validator 8 custom violation messages do not evaluate EL and an unbalanced brace only logs a warning, so there is no injection or interpolation crash there.

▎ Example: The Duration.parse fallback now accepts values the old regex never could, like a negative duration PT-1H or a zero or sub second duration PT0S or PT0.5S. The duration branch in WaitTaskMapper at 100 to 106 does not floor the result the way the until branch does at 114 to 117, so a negative duration sets callbackAfterSeconds to a negative value and a waitTimeout in the past, and the WAIT completes immediately instead of waiting.

Suggestion

Flooring the computed seconds at zero in the duration branch, or rejecting non positive durations in parseDuration, would keep the two paths consistent. A couple of tests for the negative and zero and sub second cases, plus one assertion on the new constraint message, would round it out since the added tests only cover the happy path values.

NOTE

None of this blocks the fix.

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.

WAIT task: misleading error 'date or duration is null' when ISO-8601 duration format is used

3 participants