{"record":{"id":"910d2ebb92f6d443","repo":"linlinjava/litemall","slug":"showtype","errorCode":null,"errorMessage":"showType不支持","messagePattern":"showType不支持","errorType":"exception","errorClass":"RuntimeException","httpStatus":500,"severity":"error","filePath":"litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCommentService.java","lineNumber":35,"sourceCode":"    private LitemallCommentMapper commentMapper;\n\n    public List<LitemallComment> queryGoodsByGid(Integer id, int offset, int limit) {\n        LitemallCommentExample example = new LitemallCommentExample();\n        example.setOrderByClause(LitemallComment.Column.addTime.desc());\n        example.or().andValueIdEqualTo(id).andTypeEqualTo((byte) 0).andDeletedEqualTo(false);\n        PageHelper.startPage(offset, limit);\n        return commentMapper.selectByExample(example);\n    }\n\n    public List<LitemallComment> query(Byte type, Integer valueId, Integer showType, Integer offset, Integer limit) {\n        LitemallCommentExample example = new LitemallCommentExample();\n        example.setOrderByClause(LitemallComment.Column.addTime.desc());\n        if (showType == 0) {\n            example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andDeletedEqualTo(false);\n        } else if (showType == 1) {\n            example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andHasPictureEqualTo(true).andDeletedEqualTo(false);\n        } else {\n            throw new RuntimeException(\"showType不支持\");\n        }\n        PageHelper.startPage(offset, limit);\n        return commentMapper.selectByExample(example);\n    }\n\n    public int count(Byte type, Integer valueId, Integer showType) {\n        LitemallCommentExample example = new LitemallCommentExample();\n        if (showType == 0) {\n            example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andDeletedEqualTo(false);\n        } else if (showType == 1) {\n            example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andHasPictureEqualTo(true).andDeletedEqualTo(false);\n        } else {\n            throw new RuntimeException(\"showType不支持\");\n        }\n        return (int) commentMapper.countByExample(example);\n    }\n\n    public int save(LitemallComment comment) {","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/linlinjava/litemall/blob/a1ef964a718b7277925b19ea26afe78ea3a1d325/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCommentService.java#L17-L53","documentation":"LitemallCommentService.query builds the comment-list query for the wx API and only accepts showType 0 (all comments) or 1 (comments with pictures). Any other value is a programming/input error, so the service throws a plain RuntimeException with the message 'showType不支持' (showType not supported). Because it is a RuntimeException it propagates to the Spring MVC layer and becomes a 500 unless the controller validates first. The same check is duplicated in count() so query and count fail together on bad input.","triggerScenarios":"Calling GET /wx/comment/list (or any code path into LitemallCommentService.query) with a showType parameter other than 0 or 1, e.g. showType=2 or showType=-1. Also any caller that passes a null-unboxed Integer or a newly invented filter value without extending this if/else chain.","commonSituations":"Frontend adds a new comment filter (e.g. 'only negative comments') and sends showType=2 while the backend if/else was never extended; automated tests or scripts enumerating showType values; refactoring that renames the parameter but keeps old client code sending stale values.","solutions":["Validate showType at the controller boundary and reject values outside {0,1} with a 400-style ResponseUtil.badArgument before the service is reached.","If a new filter mode is intended, add an else-if branch for it in both query() and count() so they stay consistent.","Replace the bare RuntimeException with the project's existing exception type so the global exception handler can map it to a proper JSON error instead of HTTP 500."],"exampleFix":"// before\npublic List<LitemallComment> query(Byte type, Integer valueId, Integer showType, Integer offset, Integer limit) {\n    ...\n    } else {\n        throw new RuntimeException(\"showType不支持\");\n    }\n}\n\n// after - reject at the controller (WxCommentController.list)\nif (showType == null || (showType != 0 && showType != 1)) {\n    return ResponseUtil.badArgumentValue();\n}\n// service keeps its branch logic unchanged","handlingStrategy":"validation","validationCode":"// in WxCommentController before calling the service\nif (showType == null || (showType != 0 && showType != 1)) {\n    return ResponseUtil.badArgumentValue();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Whitelist showType values at every controller that forwards it; treat new filter modes as an API contract change requiring both query() and count() updates.","Add a unit test enumerating showType = -1, 2, null to lock in the accepted domain."],"tags":["validation","input-validation","comment-service","litemall"],"backgroundTag":null,"analyzedSha":"a1ef964a718b7277925b19ea26afe78ea3a1d325","analyzedAt":"2026-08-14T12:39:46.078Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}