{"record":{"id":"d4a73059cae1631f","repo":"wuyouzhuguli/SpringAll","slug":"error-d4a730","errorCode":null,"errorMessage":"验证码不能为空！","messagePattern":"验证码不能为空！","errorType":"exception","errorClass":"ValidateCodeException","httpStatus":null,"severity":"warning","filePath":"38.Spring-Security-SmsCode/src/main/java/cc/mrbird/validate/smscode/SmsCodeFilter.java","lineNumber":51,"sourceCode":"                && StringUtils.equalsIgnoreCase(httpServletRequest.getMethod(), \"post\")) {\n            try {\n                validateCode(new ServletWebRequest(httpServletRequest));\n            } catch (ValidateCodeException e) {\n                authenticationFailureHandler.onAuthenticationFailure(httpServletRequest, httpServletResponse, e);\n                return;\n            }\n        }\n        filterChain.doFilter(httpServletRequest, httpServletResponse);\n    }\n\n    private void validateCode(ServletWebRequest servletWebRequest) throws ServletRequestBindingException {\n        String smsCodeInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), \"smsCode\");\n        String mobileInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), \"smsCode\");\n\n        SmsCode codeInSession = (SmsCode) sessionStrategy.getAttribute(servletWebRequest, ValidateController.SESSION_KEY_SMS_CODE + mobileInRequest);\n\n        if (StringUtils.isBlank(smsCodeInRequest)) {\n            throw new ValidateCodeException(\"验证码不能为空！\");\n        }\n        if (codeInSession == null) {\n            throw new ValidateCodeException(\"验证码不存在！\");\n        }\n        if (codeInSession.isExpire()) {\n            sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);\n            throw new ValidateCodeException(\"验证码已过期！\");\n        }\n        if (!StringUtils.equalsIgnoreCase(codeInSession.getCode(), smsCodeInRequest)) {\n            throw new ValidateCodeException(\"验证码不正确！\");\n        }\n        sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);\n\n    }\n}","sourceCodeStart":33,"sourceCodeEnd":66,"githubUrl":"https://github.com/wuyouzhuguli/SpringAll/blob/614d2578d9495acf53cc02f2dee9c6131cc5e51a/38.Spring-Security-SmsCode/src/main/java/cc/mrbird/validate/smscode/SmsCodeFilter.java#L33-L66","documentation":"ValidateCodeException thrown by SmsCodeFilter.validateCode() (module 38) when the submitted smsCode request parameter is null or blank. This filter runs before /login/mobile; on failure it delegates to authenticationFailureHandler. Note the filter reads the parameter named 'smsCode' here, so the form field must be named exactly that.","triggerScenarios":"POST to /login/mobile with the smsCode form field missing, empty, or whitespace-only.","commonSituations":"Form omits the smsCode input; field name is not 'smsCode' (e.g., 'code'); test client does not send smsCode; the SMS code was never entered.","solutions":["Add <input type=\"text\" name=\"smsCode\"> to the mobile login form and submit a non-empty value.","Confirm the request parameter name matches the filter's getStringParameter(...,\"smsCode\").","Add client-side required-field validation before submit.","In tests, always include a non-empty smsCode parameter."],"exampleFix":"// before\n<form action=\"/login/mobile\" method=\"post\">\n  <input name=\"mobile\"/>\n  <!-- smsCode field missing -->\n</form>\n\n// after\n<form action=\"/login/mobile\" method=\"post\">\n  <input name=\"mobile\"/>\n  <input type=\"text\" name=\"smsCode\" required/>\n</form>","handlingStrategy":"validation","validationCode":"// front-end guard before submitting the mobile login form\nif (!form.smsCode || form.smsCode.trim() === '') {\n    showError('请输入短信验证码');\n    return;\n}\nform.submit();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Mark the smsCode input required and disable submit until filled.","Match the form field name attribute exactly to the parameter the filter reads ('smsCode').","Include a non-empty smsCode in every SMS-login integration test."],"tags":["spring-security","sms-code","captcha","validation","form"],"backgroundTag":null,"analyzedSha":"614d2578d9495acf53cc02f2dee9c6131cc5e51a","analyzedAt":"2026-08-14T04:40:03.488Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}