-
Notifications
You must be signed in to change notification settings - Fork 60
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
fix: Replace deprecated protobuf methods. #2764
Merged
+2
−4
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
53549f6
fix: Replace deprecated protobuf methods.
blakeli0 5a2060d
fix: Use getRealContainingOneof() == null to replace isSynthetic()
blakeli0 8b7f3f8
Merge branch 'main' into fix-deprecated-proto-methods
blakeli0 0d45723
Merge branch 'main' into fix-deprecated-proto-methods
blakeli0 28b1139
fix: format
blakeli0 17390e8
Merge branch 'main' into fix-deprecated-proto-methods
blakeli0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this just be
fieldDescriptor.getRealContainingOneof() == null)
? The implementation looks like it's already checking forfieldDescriptor.getContaintingOneof() != null
: https://github.com/protocolbuffers/protobuf/blob/dde03553c92867184ff5d351b7f087c052f39459/java/core/src/main/java/com/google/protobuf/Descriptors.java#L1435-L1438There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a fieldDescriptor does not contain any oneof(real or synthetic) field,
fieldDescriptor.getRealContainingOneof() == null
would return true, butfieldDescriptor.getContainingOneof() != null && fieldDescriptor.getRealContainingOneof() == null
would return false.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. It needs to check that it's a oneOf before checking for the optional implementation or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That being said, based on the field name
isProto3Optional
, I'm not sure the current logic is what it intended to be. I feel likefieldDescriptor.isOptional()
may make more sense but it would introduce changes to the generated code. So I decided to go with the safest approach for now, and we can improve it in the future if we see issues.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, the more I look at this, the more I'm confusing myself. My assumption is that this logic is for code written with pre protobuf v3.15 compatibility in mind (i.e. people writing their own optional workaround -- writing their own oneof with a single field).
Looking at the implementation of isOptional makes it seems like it should work except for the optional workaround case (i.e. writing their own oneof with a single field).
I'm not entirely sure if protoc would have something like this marked as synthetic. This is where the user explicitly writes their optional workaround:
I know that under the hood that an
optional int32 foo
is converted to it above, but I'm not sure the descriptor marks things correctly if the user explicitly writes it out. I'm guessing this is the case since they had backwards compatibility in mind and I'll probably need to test this myself whenever I get some time.I think the method probably should be:
but the existing implementation should work and this can be something we look again in the future.