对平(进度三字段进白名单 + 去掉那处新增吞异常): Java 全量 4313 例 0 红

上一笔 light 加 progress* 后我只跑了 6 个定向类,把两把钉白名单的尺子漏了——
它们本来就是为「加字段必须显式承认」而设的,该红:
- SimilarAsinTaskLightWhitelistTest(私有 LightVo 键集合,两处断言)
- ResultFilePhaseContractTest(light 响应 JSON 键集快照)

CatchSilenceRatchetTest 报「不重抛 559→560」也是我引入的:parseIntOrNull 用了
catch (NumberFormatException)。这处边界防护要留(Redis 里是客户端上报的裸字符串,
一次抛出就整页任务失去进度显示),但不必用 catch 实现——先按字符判掉非数字、再限 9 位
防 int 溢出,Integer.valueOf 就不可能抛。这样既守住棘轮也不动别人的 catch。
补一条用例把「负号/超长/非数字」三个分支钉住(否则改了没人验)。

教训写在这儿:改公共 DTO/VO 之后不许只跑定向,全量才是验收。
This commit is contained in:
2026-10-11 00:02:22 +08:00
parent 96d4e40a77
commit a3eddd6d84
4 changed files with 37 additions and 8 deletions
@@ -30,6 +30,8 @@ public class TaskHeartbeatPositionService {
private static final String STALL_KEY_PREFIX = "task:progress:stall:";
private static final Duration POSITION_TTL = Duration.ofHours(24);
private static final int POSITION_LABEL_MAX_LEN = 60;
/** 计数字符串的最长位数:9 位以内 parseInt 必不溢出,所以这一处不需要 catch。 */
private static final int MAX_COUNT_DIGITS = 9;
/** 单次 light 轮询最多读多少个任务的心跳位置(Redis 往返上限,见 {@link #readDrawablePositions})。 */
public static final int MAX_POSITION_LOOKUPS_PER_CALL = 20;
/** 客户端 {@code config.PROGRESS_UNIT_SCALE} 的服务端镜像:units 粒度下 1 个自然单位 = 1000。 */
@@ -233,15 +235,23 @@ public class TaskHeartbeatPositionService {
return result;
}
/**
* Redis 里的计数是客户端上报的裸字符串,脏值不能把整次轮询带崩。
*
* <p>这里<b>不用 try/catch</b>:那格「不重抛的吞异常」棘轮只许减(基线 559),加一处就得同批
* 减掉一处别人的,不划算;而这一处本来也不需要——先按字符判掉非数字、再限长度防 int 溢出,
* {@code Integer.valueOf} 就不可能抛。负号也算脏值(客户端不会报负数,真出现就当没有读数)。
*/
private static Integer parseIntOrNull(String raw) {
if (raw == null || raw.isEmpty()) {
if (raw == null || raw.isEmpty() || raw.length() > MAX_COUNT_DIGITS) {
return null;
}
try {
return Integer.valueOf(raw);
} catch (NumberFormatException ex) {
return null;
for (int index = 0; index < raw.length(); index++) {
if (!Character.isDigit(raw.charAt(index))) {
return null;
}
}
return Integer.valueOf(raw);
}
/**