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

Cleanup various bits of Google.Protobuf #6674

Merged

Conversation

ObsidianMinor
Copy link
Contributor

While adding nullable annotations throughout the lib, I found a few missing null-checks and some IsInitialized checks accidentally left in MessageParser. Additionally, ExtensionCollection.CrossLink did some unnecessary things so this simplifies that.

@ObsidianMinor
Copy link
Contributor Author

Could you possibly review this @jtattermusch?

@jtattermusch
Copy link
Contributor

@ObsidianMinor there's a conflict

Remove IsInitialized checks accidentally left in MessageParser
Simplify ExtensionCollection.CrossLink
@ObsidianMinor
Copy link
Contributor Author

Fixed

@jtattermusch
Copy link
Contributor

Is this purely cosmetic or does it actually fix any user-visible bugs?

declarationOrder.Add(descriptor.ExtendeeType, new List<FieldDescriptor>());
}
IList<FieldDescriptor> list;
if (!declarationOrder.TryGetValue(descriptor.ExtendeeType, out list))
Copy link
Contributor

Choose a reason for hiding this comment

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

  • in protobuf codebase, always use curly brackets for if statements (single statements ifs and loops are considered dangerous).
  • I think
list = new List<FieldDescriptor>();
declarationOrder.Add(......., list);

is more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could we add an editorconfig with csharp_prefer_braces enabled to prevent style issues like this and others in the future? In another PR of course.

Copy link
Contributor

Choose a reason for hiding this comment

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

At some point, I'd like to add a set of rules to enforce code style in the protobuf C# codebase. I'm not sure what the best approach is (there are multiple ways of doing this).

@@ -261,6 +261,16 @@ public void RequiredFields()
Assert.True(message.IsInitialized());
}

// Code was accidentally left in message parser that threw exceptions when missing required fields after parsing.
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for adding the comment.
nit: Use /// <summary> block for comments outside the method body.

Copy link
Contributor

@jtattermusch jtattermusch left a comment

Choose a reason for hiding this comment

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

LGTM after changing the comment style to <summary>.

@jtattermusch jtattermusch merged commit 20b7fab into protocolbuffers:master Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants