{"record":{"id":"8de3bcf2019a78ea","repo":"dromara/Sa-Token","slug":"jwt-8de3bc","errorCode":null,"errorMessage":"jwt 字符串不可为空","messagePattern":"jwt 字符串不可为空","errorType":"validation","errorClass":"SaJwtException","httpStatus":null,"severity":"error","filePath":"sa-token-plugin/sa-token-jwt/src/main/java/cn/dev33/satoken/jwt/SaJwtTemplate.java","lineNumber":178,"sourceCode":"    /**\n     * jwt 解析\n\t *\n     * @param token Jwt-Token值 \n     * @param loginType 登录类型 \n     * @param keyt 秘钥\n     * @param isCheckTimeout 是否校验 timeout 字段\n     * @return 解析后的jwt 对象 \n     */\n    public JWT parseToken(String token, String loginType, String keyt, boolean isCheckTimeout) {\n\n    \t// 秘钥不可以为空\n    \tif(SaFoxUtil.isEmpty(keyt)) {\n    \t\tthrow new SaJwtException(\"请配置 jwt 秘钥\");\n    \t}\n\n    \t// 如果token为null \n    \tif(token == null) {\n    \t\tthrow new SaJwtException(\"jwt 字符串不可为空\");\n    \t}\n    \t\n    \t// 解析 \n    \tJWT jwt;\n    \ttry {\n    \t\tjwt = JWT.of(token);\n\t\t} catch (JWTException | JSONException e) {\n    \t\tthrow new SaJwtException(\"jwt 解析失败：\" + token, e).setCode(SaJwtErrorCode.CODE_30201);\n\t\t}\n    \tJSONObject payloads = jwt.getPayloads();\n    \t\n    \t// 校验 Token 签名\n\t\tboolean verify = jwt.setSigner(createSigner(keyt)).verify();\n    \tif( ! verify) {\n    \t\tthrow new SaJwtException(\"jwt 签名无效：\" + token).setCode(SaJwtErrorCode.CODE_30202);\n    \t}\n\n    \t// 校验 loginType ","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/dromara/Sa-Token/blob/ac2c7f6e94a78573cf0bcb932dd8b04e68fad189/sa-token-plugin/sa-token-jwt/src/main/java/cn/dev33/satoken/jwt/SaJwtTemplate.java#L160-L196","documentation":"Thrown by SaJwtTemplate.parseToken when the token argument is null (before any parsing is attempted). It is a simple null-guard so that downstream hutool JWT.of(...) never receives null. No specific error code is set.","triggerScenarios":"Calling parseToken/getPayloads with a null token string — typically because the request carried no token and the framework passed the raw (null) value through.","commonSituations":"API endpoint hit without an Authorization/satoken header; token cookie missing so the read returns null; client code variable for the token never initialized; custom filters that forward null instead of rejecting earlier.","solutions":["Ensure the client sends the token (header/cookie/param per your token-style config)","Reject missing tokens earlier in a filter/interceptor before JWT parsing","Null-check the token value in your wrapper code before calling parseToken"],"exampleFix":"// before\nString token = request.getHeader(\"Authorization\"); // null when absent\njwtTemplate.parseToken(token, \"login\", secret, true); // throws\n\n// after\nString token = request.getHeader(\"Authorization\");\nif (SaFoxUtil.isEmpty(token)) {\n    throw new SaTokenException(\"missing token\"); // handle at the boundary\n}\njwtTemplate.parseToken(token, \"login\", secret, true);","handlingStrategy":"validation","validationCode":"String token = request.getHeader(\"Authorization\");\nif (SaFoxUtil.isEmpty(token)) {\n    response.sendError(401);\n    return;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reject token-less requests in a filter before any StpLogic/JWT call","Keep token extraction in one helper that returns Optional<String> and short-circuits"],"tags":["sa-token","jwt","validation","null-check"],"backgroundTag":null,"analyzedSha":"ac2c7f6e94a78573cf0bcb932dd8b04e68fad189","analyzedAt":"2026-08-14T14:36:10.271Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}