linlinjava/litemall · error · RuntimeException

showType不支持

Error message

showType不支持

What it means

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.

Source

Thrown at litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCommentService.java:35

    private LitemallCommentMapper commentMapper;

    public List<LitemallComment> queryGoodsByGid(Integer id, int offset, int limit) {
        LitemallCommentExample example = new LitemallCommentExample();
        example.setOrderByClause(LitemallComment.Column.addTime.desc());
        example.or().andValueIdEqualTo(id).andTypeEqualTo((byte) 0).andDeletedEqualTo(false);
        PageHelper.startPage(offset, limit);
        return commentMapper.selectByExample(example);
    }

    public List<LitemallComment> query(Byte type, Integer valueId, Integer showType, Integer offset, Integer limit) {
        LitemallCommentExample example = new LitemallCommentExample();
        example.setOrderByClause(LitemallComment.Column.addTime.desc());
        if (showType == 0) {
            example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andDeletedEqualTo(false);
        } else if (showType == 1) {
            example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andHasPictureEqualTo(true).andDeletedEqualTo(false);
        } else {
            throw new RuntimeException("showType不支持");
        }
        PageHelper.startPage(offset, limit);
        return commentMapper.selectByExample(example);
    }

    public int count(Byte type, Integer valueId, Integer showType) {
        LitemallCommentExample example = new LitemallCommentExample();
        if (showType == 0) {
            example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andDeletedEqualTo(false);
        } else if (showType == 1) {
            example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andHasPictureEqualTo(true).andDeletedEqualTo(false);
        } else {
            throw new RuntimeException("showType不支持");
        }
        return (int) commentMapper.countByExample(example);
    }

    public int save(LitemallComment comment) {

View on GitHub (pinned to a1ef964a71)

Solutions

  1. Validate showType at the controller boundary and reject values outside {0,1} with a 400-style ResponseUtil.badArgument before the service is reached.
  2. If a new filter mode is intended, add an else-if branch for it in both query() and count() so they stay consistent.
  3. 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.

Example fix

// before
public List<LitemallComment> query(Byte type, Integer valueId, Integer showType, Integer offset, Integer limit) {
    ...
    } else {
        throw new RuntimeException("showType不支持");
    }
}

// after - reject at the controller (WxCommentController.list)
if (showType == null || (showType != 0 && showType != 1)) {
    return ResponseUtil.badArgumentValue();
}
// service keeps its branch logic unchanged
Defensive patterns

Strategy: validation

Validate before calling

// in WxCommentController before calling the service
if (showType == null || (showType != 0 && showType != 1)) {
    return ResponseUtil.badArgumentValue();
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of linlinjava/litemall@a1ef964a71 (2026-08-14). Data as JSON: /api/errors/910d2ebb92f6d443. Report an issue: GitHub.