Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty repeated field in frozen message #138

Closed
alpha-se opened this issue Nov 20, 2018 · 1 comment
Closed

Empty repeated field in frozen message #138

alpha-se opened this issue Nov 20, 2018 · 1 comment

Comments

@alpha-se
Copy link

alpha-se commented Nov 20, 2018

When trying to access an empty repeated field (e.g. to check if it's empty) an error is thrown since v. 0.10.0 (introduction of GeneratedMessage.freeze()).
Problem appears to be that the empty list doesn't get initialized as such but accessing it (even trying to check it against null) is trying to create a mutable list.

I/flutter (13339): Unsupported operation: Attempted to call createRepeatedField on a read-only message (MessageList)
I/flutter (13339):
I/flutter (13339): When the exception was thrown, this was the stack:
I/flutter (13339): #0 defaultFrozenMessageModificationHandler (file:///Users/bla/flutter/.pub-cache/hosted/pub.dartlang.org/protobuf-0.10.0/lib/src/protobuf/field_set.dart:12:5)
I/flutter (13339): #1 __ReadonlyMessageListList&MessageList&ReadonlyMessageMixin._readonly (file:///Users/bla/flutter/.pub-cache/hosted/pub.dartlang.org/protobuf-0.10.0/lib/src/protobuf/readonly_message.dart:57:37)
I/flutter (13339): #2 __ReadonlyMessageList&MessageList&ReadonlyMessageMixin.createRepeatedField (file:///Users/bla/flutter/.pub-cache/hosted/pub.dartlang.org/protobuf-0.10.0/lib/src/protobuf/readonly_message.dart:23:5)
I/flutter (13339): #3 FieldInfo._createRepeatedFieldWithType (file:///Users/bla/flutter/.pub-cache/hosted/pub.dartlang.org/protobuf-0.10.0/lib/src/protobuf/field_info.dart:139:14)
I/flutter (13339): #4 _FieldSet._getDefaultList (file:///Users/bla/flutter/.pub-cache/hosted/pub.dartlang.org/protobuf-0.10.0/lib/src/protobuf/field_set.dart:185:20)
I/flutter (13339): #5 FieldSet.$getList (file:///Users/bla/flutter/.pub-cache/hosted/pub.dartlang.org/protobuf-0.10.0/lib/src/protobuf/field_set.dart:324:12)
I/flutter (13339): #6 GeneratedMessage.$_getList (file:///Users/bla/flutter/.pub-cache/hosted/pub.dartlang.org/protobuf-0.10.0/lib/src/protobuf/generated_message.dart:325:48)
I/flutter (13339): #7 MessageList.repeatedField (package:app/protos/message_list.pb.dart:55:41)

Downgrading to 0.9.1 fixes the issue.

@osa1
Copy link
Member

osa1 commented May 10, 2022

It's a bit difficult to test this without a repro, but I checked the code for 0.10 and I'm surprised that you got this stack trace because _FieldSet._getDefaultList does not call _createRepeatedFieldWithType on a frozen message: (code from 0.10 tag)

List<T> _getDefaultList<T>(FieldInfo<T> fi) {
assert(fi.isRepeated);
if (_isReadOnly) return new List.unmodifiable(const []);

So if your message is really read-only then you shouldn't get this stack trace (unless there's a but in freeze and it doesn't set the read-only flag).

In any case, 0.10 is very old and any issues with it are probably fixed so closing this issue. Please feel free to re-open (ideally with a repro) if the issue still exists.

@osa1 osa1 closed this as completed May 10, 2022
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

No branches or pull requests

2 participants