Skip to content

[BUG] MockPlugin SpEL generators share a static EvaluationContext — cross-request data race on the req variable #6881

Description

@Aias00

Description

MockHandle.httpStatusCode is declared as private Integer httpStatusCode with no default initializer (unlike RedirectHandle which defaults to 302). When a mock rule is saved without specifying httpStatusCode, Gson leaves the field null. MockPlugin.doExecute calls HttpStatus.valueOf(mockHandle.getHttpStatusCode())HttpStatus.valueOf(int) receives a null Integer, auto-unboxing throws NullPointerException. Triggered on every request matching a mock rule whose handle JSON omits or nulls httpStatusCode.

Location

  • shenyu-plugin/shenyu-plugin-mock/src/main/java/org/apache/shenyu/plugin/mock/MockPlugin.java:56
  • shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/rule/MockHandle.java:27

Impact

Every request to a mock route with a null status code returns 500 instead of the mock response.

Suggested fix

Default the field: private Integer httpStatusCode = 200; in MockHandle, or guard in MockPlugin: HttpStatus.valueOf(Optional.ofNullable(mockHandle.getHttpStatusCode()).orElse(200)).

Related existing

None — distinct from #6657 (GeneralContextPlugin NPE on null cached handle) which is about cache-miss null handle, not null field within a non-null handle.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions