jeecgboot/JeecgBoot · error · RuntimeException
url 不能为空
Error message
url 不能为空
What it means
Thrown by RestUtil.request(String,HttpMethod,...) — the overload without a timeout parameter — when the url argument is null or empty (StringUtils.isEmpty). This is a precondition guard before constructing the HTTP request.
Source
Thrown at jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RestUtil.java:206
public static ResponseEntity<JSONObject> request(String url, HttpMethod method, JSONObject variables, JSONObject params) {
return request(url, method, getHeaderApplicationJson(), variables, params, JSONObject.class);
}
/**
* 发送请求
*
* @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 参数View on GitHub (pinned to 96fb33f5ec)
Solutions
- Pass a non-empty, valid URL string; verify the source of the url value.
- Read and validate the configured endpoint before calling RestUtil.request.
- Default the URL to a known service address if it is optional.
- Catch RuntimeException at the caller and return a clear error to the user.
Example fix
// before
RestUtil.request(serviceUrl, HttpMethod.POST, headers, null, body, String.class);
// after
if (StringUtils.isBlank(serviceUrl)) {
throw new IllegalArgumentException("serviceUrl 未配置");
}
RestUtil.request(serviceUrl, HttpMethod.POST, headers, null, body, String.class); Defensive patterns
Strategy: validation
Validate before calling
if (StringUtils.isEmpty(url)) {
throw new IllegalArgumentException("url 不能为空");
} Type guard
null
Try / catch
try {
RestUtil.request(url, method, headers, variables, params, responseType);
} catch (RuntimeException e) {
log.error("HTTP 请求参数校验失败: {}", e.getMessage());
return ResponseEntity.badRequest().build();
} Prevention
- Validate URL configuration at startup.
- Default to a known service address when the URL is optional.
- Never derive URLs from unchecked user input.
When it happens
Trigger: Calling RestUtil.request(url, method, ...) where url is null, empty string, or blank; url was read from config that resolved to empty; url built from a template whose variable was unset.
Common situations: Configuration property for a downstream service URL missing in application yml; URL field left blank in an admin form that triggers an HTTP call; NPE upstream produced a null URL.
Related errors
- method 不能为空
- 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/8eb6179ba904d8ea.
Report an issue: GitHub.