paascloud/paascloud-master · error · ValidateCodeException
验证码的值不能为空
Error message
验证码的值不能为空
What it means
Fires in AbstractValidateCodeProcessor.check when the captcha parameter sent in the HTTP request (read via codeType.getParamNameOnValidate()) is blank. This is a validation guard ensuring the user actually submitted a code before it is compared against the code stored in the ValidateCodeRepository; the session code is never consulted. Client-side fix: submit the parameter matching the code type's paramNameOnValidate.
Solutions
- Client-side validate that the code input is non-empty before submitting
- Show the user a prompt asking to enter the code
- Server-side, catch ValidateCodeException and return a friendly 'code required' message
Example fix
// before
if (!smsCode) { submit(); }
// after
if (!smsCode || !smsCode.trim()) { alert('请输入验证码'); return; } Defensive patterns
Strategy: validation
Validate before calling
if (code == null || code.trim().isEmpty()) { alert('请输入验证码'); return false; } Type guard
function hasCode(v) { return typeof v === 'string' && v.trim().length > 0; } Try / catch
try { processor.validate(request); } catch (ValidateCodeException e) { bindingResult.rejectValue("smsCode", "blank", e.getMessage()); } Prevention
- Client-side required-field validation on the code input
- Disable submit until the field is filled
- Show server messages inline next to the field
When it happens
Trigger: Client submits the validate-code request with the parameter present but empty string (e.g. smsCode=).
Common situations: User clicked submit without entering the code; frontend sends empty field instead of omitting it; mobile app sending placeholder empty values.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10).
Data as JSON: /api/errors/66299c9c5f3f1bea.
Report an issue: GitHub.
Appendix: source
Thrown at paascloud-common/paascloud-security-core/src/main/java/com/paascloud/security/core/validate/code/impl/AbstractValidateCodeProcessor.java:141
*
* @param request the request
*/
@SuppressWarnings("unchecked")
@Override
public void check(ServletWebRequest request) {
ValidateCodeType codeType = getValidateCodeType();
C codeInSession = (C) validateCodeRepository.get(request, codeType);
String codeInRequest;
try {
codeInRequest = ServletRequestUtils.getStringParameter(request.getRequest(), codeType.getParamNameOnValidate());
} catch (ServletRequestBindingException e) {
throw new ValidateCodeException("获取验证码的值失败");
}
if (StringUtils.isBlank(codeInRequest)) {
throw new ValidateCodeException(codeType + "验证码的值不能为空");
}
if (codeInSession == null || codeInSession.isExpired()) {
validateCodeRepository.remove(request, codeType);
throw new ValidateCodeException(codeType + "验证码已过期");
}
if (!StringUtils.equals(codeInSession.getCode(), codeInRequest)) {
throw new ValidateCodeException(codeType + "验证码不匹配");
}
}
}
View on GitHub (pinned to 781281a950)