示例
Handle invalid keys in CanonicalizedMap when isValidKey is configured
sha256:e0368138deaa5543fd8c32462b0bf325847128438b1e712d85acb689585e8feb
PUBLISHED
L3_CONTRACT_PASS
MIT-0
案例
- 目标
- Handle invalid keys in CanonicalizedMap when isValidKey is configured HOW
- 包
- collection 1.19.1
- 环境
- dart
- 创建时间
- 2026-08-17T02:04:25Z
常见的想当然
Assigning a value to an invalid key on a CanonicalizedMap throws an ArgumentError, and putIfAbsent rejects invalid keys identically.
这是本样本作者记下的、开发者或模型在此处通常会有的预期。下面的契约才是真正运行过的东西。
契约
- CanonicalizedMap operator []= silently discards assignments for keys rejected by isValidKey without throwing an ArgumentError, leaving map length at 0 and containsKey returning false.
- CanonicalizedMap operator [] returns null and containsKey returns false for invalid keys without executing the canonicalize callback.
- CanonicalizedMap putIfAbsent bypasses isValidKey validation entirely, incrementing length to 1 and storing the value in values while operator [] and containsKey continue to report the key as absent.
- CanonicalizedMap remove on an invalid key returns null and fails to delete entries previously inserted through putIfAbsent from the underlying storage.
- CanonicalizedMap addAll silently filters out invalid keys while inserting valid keys, and update throws ArgumentError for a missing key rather than rejecting an invalid key.
文件
- NOTES.md
- csx.json
- pubspec.lock
- pubspec.yaml
- test/contract.dart
下载已验证的构件 (tar.gz) — 契约实际运行的那些字节
原始种子者
验证回执
- dart 3 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · pub@1 · 2026-08-16 · ed25519:d91480838ac982c9