dromara/Sa-Token · warning · RuntimeException
参数${key}不能为空
Error message
参数${key}不能为空 What it means
Thrown by SoMap.checkNull(String... keys) when any requested key is null under SoMap's loose null standard (null, empty string, or one of NULL_ELEMENT_LIST like "null"/"NaN"). It is a deliberate parameter-validation guard used by the OAuth2 client demo controllers to fail fast on missing input.
Source
Thrown at sa-token-demo/sa-token-demo-oauth2/sa-token-demo-oauth2-client/src/main/java/com/pj/utils/SoMap.java:525
/** 与isNull()相反 */
public boolean isNotNull(String key) {
return !isNull(key);
}
/** 指定key的value是否为null,作用同isNotNull() */
public boolean has(String key) {
return !isNull(key);
}
/** 指定value在此SoMap的判断标准中是否为null */
public boolean valueIsNull(Object value) {
return NULL_ELEMENT_LIST.contains(value);
}
/** 验证指定key不为空,为空则抛出异常 */
public SoMap checkNull(String ...keys) {
for (String key : keys) {
if(this.isNull(key)) {
throw new RuntimeException("参数" + key + "不能为空");
}
}
return this;
}
static Pattern patternNumber = Pattern.compile("[0-9]*");
/** 指定key是否为数字 */
public boolean isNumber(String key) {
String value = getString(key);
if(value == null) {
return false;
}
return patternNumber.matcher(value).matches();
}
View on GitHub (pinned to ac2c7f6e94)
Solutions
- Send all required parameters; check the exception message for the exact missing key name.
- Verify parameter names are case-sensitive matches and the body is application/x-www-form-urlencoded when posting.
- For optional fields, remove the key from the checkNull list and test with isNull(key) instead.
- Ensure getRequestSoMap() is called on the request thread (see error 104) so parameters are actually populated.
Example fix
// before
SoMap soMap = SoMap.getRequestSoMap();
soMap.checkNull("client_id", "response_type", "redirect_uri");
// after
SoMap soMap = SoMap.getRequestSoMap();
if (soMap.isNull("client_id")) {
return SaResult.error("missing client_id");
}
soMap.checkNull("response_type", "redirect_uri"); Defensive patterns
Strategy: validation
Validate before calling
for (String key : new String[]{"client_id", "response_type"}) {
if (soMap.isNull(key)) {
return SaResult.error("missing param: " + key);
}
} Prevention
- Validate at the controller boundary and return a structured 400 instead of letting checkNull's RuntimeException bubble.
- Send required params with correct case and form-encoded bodies; checkNull is case-sensitive.
When it happens
Trigger: Calling soMap.checkNull("client_id", "response_type") when the HTTP request is missing one of those parameters, or the parameter value is the literal string "null" / empty. Also fires when getRequestSoMap() was populated from a request whose parameter names don't match exactly (case-sensitive).
Common situations: OAuth2 authorize/token endpoints called with missing client_id, redirect_uri, or a form body that was not parsed (wrong Content-Type), or query vs form parameter mix-ups.
Related errors
AI-assisted analysis of dromara/Sa-Token@ac2c7f6e94 (2026-08-14).
Data as JSON: /api/errors/b3a2b559b38573bc.
Report an issue: GitHub.