binarywang/WxJava · error · IllegalArgumentException

缺少tagId参数

Error message

缺少tagId参数

What it means

Thrown as IllegalArgumentException when the tagId parameter is null in WxCpTpTagServiceImpl.get(). This is a precondition check before the tagId is interpolated into the TAG_GET URL via String.format. Passing null would produce a malformed URL, so the method fails fast.

Source

Thrown at weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpTagServiceImpl.java:80

  public void delete(String tagId) throws WxErrorException {
    String url = String.format(getWxCpTpConfigStorage().getApiUrl(TAG_DELETE), tagId);
    this.mainService.get(url, null);
  }

  @Override
  public List<WxCpTpTag> listAll() throws WxErrorException {
    String url = getWxCpTpConfigStorage().getApiUrl(TAG_LIST);
    String responseContent = this.mainService.get(url, null);
    JsonObject tmpJson = GsonParser.parse(responseContent);
    return WxCpGsonBuilder.create().fromJson(tmpJson.get("taglist"), new TypeToken<List<WxCpTpTag>>() {
      // do nothing
    }.getType());
  }

  @Override
  public WxCpTpTagGetResult get(String tagId) throws WxErrorException {
    if (tagId == null) {
      throw new IllegalArgumentException("缺少tagId参数");
    }

    String url = String.format(getWxCpTpConfigStorage().getApiUrl(TAG_GET), tagId);
    String responseContent = this.mainService.get(url, null);
    return WxCpTpTagGetResult.deserialize(responseContent);
  }

  @Override
  public WxCpTpTagAddOrRemoveUsersResult addUsers2Tag(String tagId, List<String> userIds, List<String> partyIds)
    throws WxErrorException {
    String url = getWxCpTpConfigStorage().getApiUrl(TAG_ADD_TAG_USERS);
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("tagid", tagId);
    this.addUserIdsAndPartyIdsToJson(userIds, partyIds, jsonObject);

    return WxCpTpTagAddOrRemoveUsersResult.deserialize(this.mainService.post(url, jsonObject.toString()));
  }

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Pass a non-null tagId: tagService.get("1")
  2. Validate tagId before calling: if (tagId != null) tagService.get(tagId);
  3. Trace the null source — check where the tagId variable is assigned

Example fix

// before
String tagId = getTagIdFromRequest(); // may return null
tagService.get(tagId);

// after
String tagId = getTagIdFromRequest();
if (tagId == null) {
  throw new IllegalArgumentException("tagId is required");
}
tagService.get(tagId);
Defensive patterns

Strategy: validation

Validate before calling

// Validate tagId before calling get()
if (tagId == null || tagId.isEmpty()) {
  throw new IllegalArgumentException("tagId must not be null or empty");
}
tagService.get(tagId);

Type guard

private static boolean isValidTagId(String tagId) {
  return tagId != null && !tagId.isEmpty();
}

Try / catch

try {
  tagService.get(tagId);
} catch (IllegalArgumentException e) {
  if (e.getMessage().contains("tagId")) {
    log.warn("tagId was null, skipping tag query");
    return null;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling tagService.get(null) — the caller did not supply a tag ID. Also triggers if an upstream variable holding the tag ID is null due to a data flow bug.

Common situations: Null tag ID from database or upstream API response; forgot to pass tag ID from user input; business logic producing null under certain conditions.

Related errors


AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14). Data as JSON: /api/errors/88468395266f32fd. Report an issue: GitHub.