You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Invalid current-time format skips the Mock fallback #8640
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.
(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.
Activity
wy471x commentedon Nov 27, 2026
Confirmed.
MockUtil#currentguards the custom format with aDateTimeExceptionhandler:(
shenyu-plugin-mock/.../util/MockUtil.java:150-160), butofPatternrejects an invalid pattern withIllegalArgumentException, which is not aDateTimeException, so the default-format fallback is unreachable for malformed patterns. The fallback only ever fires for formatting failures.The narrow fix is to catch
IllegalArgumentExceptionas well (orDateTimeException | 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.