Repository navigation
refactor: use CollectionCopies.unmodifiableShallowList for list copying - #1
Conversation
…ist copying Add unmodifiableShallowList() to CollectionCopies to mirror the existing unmodifiableShallowMap() method, and use it in DataPart.defensivelyCopy() instead of inlining the pattern. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
hey @kabir really thanks for this pr and very sorry for the late reply it mirrors the unmodifiableshallowmap already in collectioncopies, and closes the one pot in datapart that was still inlining the copy instead of routing through that class. i also verified it locally all 142 checks passes |
|
well verified locally no v1.0 spec recored uses List.copyOf/Map.copyOf anymore, so datapart was the last holdout , collectioncopies migration is now 100% done in v1.0. one more finding the same null-hostile pattern is all over compat-0.3 // compat-0.3/.../DataPart_v0_3.java:20
public record DataPart_v0_3(Map<String, Object> data, ...)
this.data = Map.copyOf(data); // NPEs on {"k": null}
this.metadata = metadata == null ? Map.of() : Map.copyOf(metadata);Is that intentional ? or would moving CollectionCopies into common be worth a follow-up issue? |
7898631
into
malladinagarjuna2:fix-grpc-transport-validation-and-error-message
|
@malladinagarjuna2 Not doing it in 0.3 is an oversight, so maybe create an issue to improve this there as well? |
Summary
unmodifiableShallowList()toCollectionCopies, mirroring the existingunmodifiableShallowMap()methodDataPart.defensivelyCopy()to use it instead of inliningCollections.unmodifiableList(new ArrayList<>(list))This keeps the defensive copy pattern consistent: all null-preserving copies go through
CollectionCopies.unmodifiable*methods (introduced in a2aproject#968).Test plan
DataPartTestsuite passes (list immutability, null preservation, primitives)mvn clean install -pl spec -ambuilds successfully🤖 Generated with Claude Code