Sean-Walker0 opened a new pull request, #7366: URL: https://github.com/apache/shenyu/pull/7366
<!-- Describe your PR here; e.g. Fixes #issueNo --> Found by code audit (no existing issue — happy to file one if maintainers prefer). `MockUtil#zh` samples its length with `random.nextInt(max - min - 1) + min`: - `Random#nextInt`'s bound is **exclusive**, so lengths land in `[min, max-2]` — the top two values of the requested range are never produced; - when `max == min + 1` the bound is `0` and **every call throws `IllegalArgumentException: bound must be positive`** — the mock expression `#zh(2,3)` (registered in `EvaluationContextUtil`) fails deterministically instead of returning a short Chinese string. The `en` sibling two methods below — and every other random draw in this class (`phone`, `bool`) — sample through `RandomUtil.randomInt(min, max)`, whose javadoc and implementation (`nextInt(max - min + 1) + min`) are inclusive on both ends. `zh` is the sole deviation. <!-- Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request. --> Make sure that: - [x] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide). - [x] You submit test cases (unit or integration tests) that back your changes. - [x] Your local test passed `./mvnw test -pl shenyu-plugin/shenyu-plugin-mock -am and ./mvnw checkstyle:check -pl shenyu-plugin/shenyu-plugin-mock` (module-scoped; full build left to CI). ### Modifications - `zh` now samples its length with `RandomUtil.randomInt(min, max)` like the `en` sibling (one-line change; the now-unused `java.util.Random` import is dropped). ### Verifying this change - New `MockUtilTest`: `zh(2,3)` must return lengths 2–3 (fails on current master with `IllegalArgumentException: bound must be positive` on every call) and `zh(2,5)` must reach the upper half of the range over 500 draws (master never exceeds 3). - `ExpressionGeneratorTest#testZhDataGenerate` asserted the **quoted** expression output against the raw `[min, max]` range — an assertion that only held under the truncated distribution. It now asserts the quoted content spans `[min, max]` exactly like the sibling `testEnDataGenerate` contract (`"[一-龥]{10,20}"`). - Full `shenyu-plugin-mock` module suite green (192 test classes across the reactor); checkstyle green. ### Notes - Behavior change: `#zh(min,max)` now produces lengths across the full inclusive range (previously capped at max-2) and no longer crashes for adjacent bounds like `#zh(2,3)`. - One pre-existing test was recalibrated because its bounds were an artifact of the buggy distribution (disclosed above); the en-sibling test defines the intended contract. - Orthogonal to open PRs: no open PR touches `MockUtil` or the mock generators (checked against the file lists of all 198 open PRs). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
