Add some missing null-checks
Remove IsInitialized checks accidentally left in MessageParser Simplify ExtensionCollection.CrossLink
This commit is contained in:
parent
3cae867740
commit
71c492da3c
@ -89,7 +89,7 @@ namespace Google.Protobuf
|
||||
private CodedOutputStream(byte[] buffer, int offset, int length)
|
||||
{
|
||||
this.output = null;
|
||||
this.buffer = buffer;
|
||||
this.buffer = ProtoPreconditions.CheckNotNull(buffer, nameof(buffer));
|
||||
this.position = offset;
|
||||
this.limit = offset + length;
|
||||
leaveOpen = true; // Simple way of avoiding trying to dispose of a null reference
|
||||
|
@ -133,7 +133,7 @@ namespace Google.Protobuf
|
||||
/// <param name="settings">The settings.</param>
|
||||
public JsonFormatter(Settings settings)
|
||||
{
|
||||
this.settings = settings;
|
||||
this.settings = ProtoPreconditions.CheckNotNull(settings, nameof(settings));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -110,7 +110,7 @@ namespace Google.Protobuf
|
||||
/// <param name="settings">The settings.</param>
|
||||
public JsonParser(Settings settings)
|
||||
{
|
||||
this.settings = settings;
|
||||
this.settings = ProtoPreconditions.CheckNotNull(settings, nameof(settings));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -72,7 +72,6 @@ namespace Google.Protobuf
|
||||
{
|
||||
IMessage message = factory();
|
||||
message.MergeFrom(data, DiscardUnknownFields, Extensions);
|
||||
CheckMergedRequiredFields(message);
|
||||
return message;
|
||||
}
|
||||
|
||||
@ -87,7 +86,6 @@ namespace Google.Protobuf
|
||||
{
|
||||
IMessage message = factory();
|
||||
message.MergeFrom(data, offset, length, DiscardUnknownFields, Extensions);
|
||||
CheckMergedRequiredFields(message);
|
||||
return message;
|
||||
}
|
||||
|
||||
@ -100,7 +98,6 @@ namespace Google.Protobuf
|
||||
{
|
||||
IMessage message = factory();
|
||||
message.MergeFrom(data, DiscardUnknownFields, Extensions);
|
||||
CheckMergedRequiredFields(message);
|
||||
return message;
|
||||
}
|
||||
|
||||
@ -113,7 +110,6 @@ namespace Google.Protobuf
|
||||
{
|
||||
IMessage message = factory();
|
||||
message.MergeFrom(input, DiscardUnknownFields, Extensions);
|
||||
CheckMergedRequiredFields(message);
|
||||
return message;
|
||||
}
|
||||
|
||||
@ -130,7 +126,6 @@ namespace Google.Protobuf
|
||||
{
|
||||
IMessage message = factory();
|
||||
message.MergeDelimitedFrom(input, DiscardUnknownFields, Extensions);
|
||||
CheckMergedRequiredFields(message);
|
||||
return message;
|
||||
}
|
||||
|
||||
@ -143,7 +138,6 @@ namespace Google.Protobuf
|
||||
{
|
||||
IMessage message = factory();
|
||||
MergeFrom(message, input);
|
||||
CheckMergedRequiredFields(message);
|
||||
return message;
|
||||
}
|
||||
|
||||
@ -176,12 +170,6 @@ namespace Google.Protobuf
|
||||
}
|
||||
}
|
||||
|
||||
internal static void CheckMergedRequiredFields(IMessage message)
|
||||
{
|
||||
if (!message.IsInitialized())
|
||||
throw new InvalidOperationException("Parsed message does not contain all required fields");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new message parser which optionally discards unknown fields when parsing.
|
||||
/// </summary>
|
||||
|
@ -107,13 +107,11 @@ namespace Google.Protobuf.Reflection
|
||||
{
|
||||
descriptor.CrossLink();
|
||||
|
||||
IList<FieldDescriptor> _;
|
||||
if (!declarationOrder.TryGetValue(descriptor.ExtendeeType, out _))
|
||||
{
|
||||
declarationOrder.Add(descriptor.ExtendeeType, new List<FieldDescriptor>());
|
||||
}
|
||||
IList<FieldDescriptor> list;
|
||||
if (!declarationOrder.TryGetValue(descriptor.ExtendeeType, out list))
|
||||
declarationOrder.Add(descriptor.ExtendeeType, list = new List<FieldDescriptor>());
|
||||
|
||||
declarationOrder[descriptor.ExtendeeType].Add(descriptor);
|
||||
list.Add(descriptor);
|
||||
}
|
||||
|
||||
extensionsByTypeInDeclarationOrder = declarationOrder
|
||||
|
Loading…
Reference in New Issue
Block a user