Skip to content

[BUG] Invalid current-time format skips the Mock fallback #8640

Backlog

Description

@wozhenbang2004

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

The Mock plugin falls back to its default date format when a custom format cannot format the current time. A malformed pattern is rejected earlier by DateTimeFormatter.ofPattern() and throws IllegalArgumentException instead. The fallback is not reached.

Expected Behavior

Use the existing default format for a malformed pattern. Keep valid custom patterns and the existing fallback for unsupported date-time fields unchanged.

Steps To Reproduce

Evaluate a Mock current-time expression with the custom date pattern yyyy-MM-dd ', which has an unmatched quote. The date formatter throws rather than returning a default-formatted timestamp. The patch includes a targeted MockUtilTest for this case.

Environment

ShenYu version(s):

Debug logs

No response

Anything else?

No response

Activity

  1. added
    type: bug
    on Nov 26, 2026
  2. wy471x commented on Nov 27, 2026

    @wy471x
    Contributor

    Confirmed. MockUtil#current guards the custom format with a DateTimeException handler:

    try {
        return DateTimeFormatter.ofPattern(format).format(now);
    } catch (DateTimeException e) {
        ... return DateTimeFormatter.ofPattern(DEFAULT_FORMAT).format(now);
    }

    (shenyu-plugin-mock/.../util/MockUtil.java:150-160), but ofPattern rejects an invalid pattern with IllegalArgumentException, which is not a DateTimeException, so the default-format fallback is unreachable for malformed patterns. The fallback only ever fires for formatting failures.

    The narrow fix is to catch IllegalArgumentException as well (or DateTimeException | IllegalArgumentException) around the pattern construction, keeping the existing warning. Please keep the behaviour for valid patterns byte-identical, and let the test assert the returned value against the default format rather than only that no exception is thrown.

    One question worth answering in the PR: should a malformed pattern be a warning (current design, silent degradation) or a rule validation error in Admin? Silently formatting differently is surprising for a Mock response, so at minimum the warning should name the rejected pattern. A PR is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions