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.
Description
MockHandle.httpStatusCodeis declared asprivate Integer httpStatusCodewith no default initializer (unlikeRedirectHandlewhich defaults to 302). When a mock rule is saved without specifyinghttpStatusCode, Gson leaves the field null.MockPlugin.doExecutecallsHttpStatus.valueOf(mockHandle.getHttpStatusCode())—HttpStatus.valueOf(int)receives a nullInteger, auto-unboxing throwsNullPointerException. Triggered on every request matching a mock rule whose handle JSON omits or nullshttpStatusCode.Location
shenyu-plugin/shenyu-plugin-mock/src/main/java/org/apache/shenyu/plugin/mock/MockPlugin.java:56shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/rule/MockHandle.java:27Impact
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;inMockHandle, or guard inMockPlugin: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.