jeecgboot/JeecgBoot · error · RuntimeException
method 不能为空
Error message
method 不能为空
What it means
Thrown by RestUtil.request(String,HttpMethod,...) — the overload without a timeout parameter — when the method (HttpMethod) argument is null. A null HTTP method is rejected before the request is built.
Source
Thrown at jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RestUtil.java:209
/**
* 发送请求
*
* @param url 请求地址
* @param method 请求方式
* @param headers 请求头 可空
* @param variables 请求url参数 可空
* @param params 请求body参数 可空
* @param responseType 返回类型
* @return ResponseEntity<responseType>
*/
public static <T> ResponseEntity<T> request(String url, HttpMethod method, HttpHeaders headers, JSONObject variables, Object params, Class<T> responseType) {
log.debug(" RestUtil --- request --- url = "+ url);
if (StringUtils.isEmpty(url)) {
throw new RuntimeException("url 不能为空");
}
if (method == null) {
throw new RuntimeException("method 不能为空");
}
if (headers == null) {
headers = new HttpHeaders();
}
// 请求体
String body = "";
if (params != null) {
if (params instanceof JSONObject) {
body = ((JSONObject) params).toJSONString();
} else {
body = params.toString();
}
}
// 拼接 url 参数
if (variables != null && !variables.isEmpty()) {
url += ("?" + asUrlVariables(variables));
}View on GitHub (pinned to 96fb33f5ec)
Solutions
- Pass a non-null HttpMethod (GET, POST, PUT, DELETE, etc.).
- Map the incoming method string with a default of HttpMethod.GET or HttpMethod.POST when it is absent/unknown.
- Validate method is non-null before the call.
Example fix
// before
HttpMethod method = mapMethod(request.getMethod()); // may be null
RestUtil.request(url, method, headers, null, body, String.class);
// after
HttpMethod method = mapMethod(request.getMethod());
if (method == null) {
method = HttpMethod.GET;
}
RestUtil.request(url, method, headers, null, body, String.class); Defensive patterns
Strategy: validation
Validate before calling
if (method == null) {
throw new IllegalArgumentException("method 不能为空");
} Type guard
null
Try / catch
try {
RestUtil.request(url, method, headers, variables, params, responseType);
} catch (RuntimeException e) {
log.error("HTTP method 校验失败: {}", e.getMessage());
return ResponseEntity.badRequest().build();
} Prevention
- Always supply a non-null HttpMethod enum.
- Provide a default method when mapping from strings.
- Validate method before building the request.
When it happens
Trigger: Calling RestUtil.request(url, method, ...) with method == null; method was derived from user/config input that was not mapped to an HttpMethod enum value.
Common situations: Caller passes a String method that failed to convert to HttpMethod; a switch/map mapping request method names returned null; default case missing when deriving HttpMethod.
Related errors
- url 不能为空
- sys.api.apiRequestFailed
- 模板缺少参数:${item}
- The file name can not null
- 非法存储路径,路径包含遍历字符: {storePath}
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/195d0de7400e2c74.
Report an issue: GitHub.