Skip to content

refactor: use CollectionCopies.unmodifiableShallowList for list copying - #1

Merged
malladinagarjuna2 merged 1 commit into
malladinagarjuna2:fix-grpc-transport-validation-and-error-messagefrom
kabir:fix-collection-copies-list
Aug 15, 2026
Merged

malladinagarjuna2 merged 1 commit into
malladinagarjuna2:fix-grpc-transport-validation-and-error-messagefrom
kabir:fix-collection-copies-list

Conversation

@kabir

@kabir kabir commented Aug 11, 2026

Copy link
Copy Markdown

Summary

  • Adds unmodifiableShallowList() to CollectionCopies, mirroring the existing unmodifiableShallowMap() method
  • Updates DataPart.defensivelyCopy() to use it instead of inlining Collections.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

  • Existing DataPartTest suite passes (list immutability, null preservation, primitives)
  • mvn clean install -pl spec -am builds successfully

🤖 Generated with Claude Code

…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]>
@malladinagarjuna2

malladinagarjuna2 commented Aug 15, 2026 •

Copy link
Copy Markdown
Owner

hey @kabir really thanks for this pr and very sorry for the late reply
its a fair point,
you are right that unmodifableshallowlist is byte for byte the exoresson it replaces, so behaviour is identical, including preserving null elements which listcopy of would NPE on, the javadoc exactly says that

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

@malladinagarjuna2

malladinagarjuna2 commented Aug 15, 2026 •

Copy link
Copy Markdown
Owner

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
that is the impactful one, compat-0.3/spec uses copyof in many places
including

// 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?

@malladinagarjuna2
malladinagarjuna2 merged commit 7898631 into malladinagarjuna2:fix-grpc-transport-validation-and-error-message Aug 15, 2026
9 checks passed
@kabir

kabir commented Aug 18, 2026

Copy link
Copy Markdown
Author

@malladinagarjuna2 Not doing it in 0.3 is an oversight, so maybe create an issue to improve this there as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants