binarywang/WxJava · error · WxErrorException

请仔细配置会话存档文件路径!!

Error message

请仔细配置会话存档文件路径!!

What it means

Thrown as WxErrorException (checked) in createSdk() when the parsed libFiles array has length <= 0 after splitting the suffix portion of msgAuditLibPath by comma. Note: in practice this check is effectively unreachable because String.split(",") on an empty string still returns a single-element array [""], so libFiles.length is always >= 1. The intended guard is to catch a malformed path where no library filenames were specified after the directory prefix.

Solutions

  1. Set msgAuditLibPath to include the actual library filename(s) after the directory path, not just the directory.
  2. Verify the path format: directory + library filenames separated by commas (e.g., "/opt/wecom/libWeWorkFinanceSdk.so").
  3. If the error does not fire but loading fails, check that the path string after the last slash is non-empty and matches a real file.

Example fix

// before
config.setMsgAuditLibPath("/opt/wecom/finance/"); // no filename after slash

// after
config.setMsgAuditLibPath("/opt/wecom/finance/libWeWorkFinanceSdk_Java.so");
Defensive patterns

Strategy: validation

Validate before calling

String libPath = cpService.getWxCpConfigStorage().getMsgAuditLibPath();
if (StringUtils.isNotEmpty(libPath)) {
    String suffix = libPath.replace("\\", "/");
    suffix = suffix.substring(suffix.lastIndexOf("/") + 1);
    if (suffix.isEmpty()) {
        throw new IllegalStateException("msgAuditLibPath must include library filenames, not just a directory");
    }
}

Prevention

When it happens

Trigger: Conceptually triggered when msgAuditLibPath's filename portion (after the last slash) is empty, meaning the path ends with a trailing slash and no actual library file names. In practice the split(",") call makes this nearly impossible to trigger, so the guard does not fire as intended.

Common situations: Developer configures msgAuditLibPath as a directory path ending with a slash (e.g., "/opt/wecom/finance/") instead of a full path to the library file(s). However, due to the split behavior, this error may not actually fire; instead a later UnsatisfiedLinkError or loading failure would occur.

Related errors


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

Appendix: source

Thrown at weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMsgAuditServiceImpl.java:124

    String configPath = configStorage.getMsgAuditLibPath();
    if (StringUtils.isEmpty(configPath)) {
      throw new WxErrorException("请配置会话存档sdk文件的路径,不要配错了!!");
    }

    // 替换斜杠
    String replacePath = configPath.replace("\\", "/");
    // 获取最后一个斜杠的下标,用作分割路径
    int lastIndex = replacePath.lastIndexOf("/") + 1;
    // 获取完整路径的前缀路径
    String prefixPath = replacePath.substring(0, lastIndex);
    // 获取后缀的所有文件,目的遍历所有文件
    String suffixFiles = replacePath.substring(lastIndex);

    // 包含so文件
    String[] libFiles = suffixFiles.split(",");
    if (libFiles.length <= 0) {
      throw new WxErrorException("请仔细配置会话存档文件路径!!");
    }

    List<String> libList = Arrays.asList(libFiles);
    // 判断windows系统会话存档sdk中dll的加载,因为会互相依赖所以是有顺序的,否则会导致无法加载sdk #2598
    List<String> osLib = new LinkedList<>();
    List<String> fileLib = new ArrayList<>();
    libList.forEach(s -> {
      if (s.contains("lib")) {
        osLib.add(s);
      } else {
        fileLib.add(s);
      }
    });
    osLib.addAll(fileLib);

    Finance.loadingLibraries(osLib, prefixPath);
    long sdk = Finance.NewSdk();
    // 因为会话存档单独有个secret,优先使用会话存档的secret

View on GitHub (pinned to 1c43293a3c)