Skip to content

Conversation

@osa1
Copy link
Member

@osa1 osa1 commented Oct 14, 2025

When an extension field set isn't initialized before freezing the message:

  • addExtension allows adding and modifying extensions.
  • getExtension returns non-frozen defaults that can be modified.

Fix this by initializing the extension field set as frozen when the parent message is frozen.

Secondly, extension field set returns differently typed lists when it's frozen and not frozen. Fix this by always creating the list via the field's FieldInfo.

Also refactor the code a little bit: GeneratedMessage by-passes a layer of abstraction and accesses unknown field sets directly. Instead make it call FieldSet always.

New FieldSet methods are added as public (without an underscore in the name) to make it clear that they're a public interface (can be called from GeneratedMessage).

(Ideally FieldSet should be a separate library, but that requires a lot of refactoring to split the parts into libraries.)

Also remove duplicate "is repeated" and "ensure writable" checks when modifying extension fields.


cl/819146715

@osa1 osa1 force-pushed the extension_modifications branch from b450740 to 8335677 Compare October 14, 2025 10:38

* Fix `GeneratedMessage.getExtension` returning differently typed lists when the
message extension field set is initialized and frozen and initialized but not
frozen. ([#1062])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this is not fixing a bug caused by the previous entry, it exists in the master branch independently of the other bugs. However the repro is different in the master branch vs. this branch.

@osa1 osa1 marked this pull request as ready for review October 17, 2025 10:33
@osa1 osa1 requested a review from sigurdm October 17, 2025 10:33
@osa1 osa1 merged commit 78cf743 into google:master Oct 20, 2025
12 checks passed
@osa1 osa1 deleted the extension_modifications branch October 20, 2025 09:46
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Oct 21, 2025
Revisions updated by `dart tools/rev_sdk_deps.dart`.

protobuf (https://github.com/dart-lang/protobuf/compare/14bbd0b..78cf743):
  78cf743  2025-10-20  Ömer Sinan Ağacan  Fix a few extension field bugs (google/protobuf.dart#1062)

tools (https://github.com/dart-lang/tools/compare/f5920a2..d0941a3):
  d0941a35  2025-10-17  Morgan :)  Unify watcher tests (dart-lang/tools#2211)
  fa978cd2  2025-10-17  Morgan :)  Remove backup expectations (dart-lang/tools#2209)

web (https://github.com/dart-lang/web/compare/816abcc..5a7d0be):
  5a7d0be  2025-10-16  Srujan Gaddam  Initial commit of package:js_interop 0.1.0-beta (dart-lang/web#476)

webdev (https://github.com/dart-lang/webdev/compare/2517aa9..82b3855):
  82b38557  2025-10-20  Jessy Yameogo  [DWDS] Fixes hot reload/restart crashes after closing browser tab on web-server device  (dart-lang/webdev#2699)

Change-Id: I98c840892d243f3dc34f9409956d8726ff84238a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456040
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Devon Carew <devoncarew@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
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