Skip to content

Commit

Permalink
Avoid NullReferenceException in Message.TargetAddress (#6635)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenBond committed Jul 7, 2020
1 parent 29400a2 commit f2334a7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Orleans.Core.Abstractions/IDs/ActivationAddress.cs
Expand Up @@ -30,7 +30,7 @@ public static ActivationAddress NewActivationAddress(SiloAddress silo, GrainId g
public static ActivationAddress GetAddress(SiloAddress silo, GrainId grain, ActivationId activation)
{
// Silo part is not mandatory
if (grain == null) throw new ArgumentNullException("grain");
if (grain.IsDefault) throw new ArgumentNullException("grain");

return new ActivationAddress(silo, grain, activation);
}
Expand Down
12 changes: 11 additions & 1 deletion src/Orleans.Core/Messaging/Message.cs
Expand Up @@ -168,7 +168,17 @@ public ActivationId TargetActivation

public ActivationAddress TargetAddress
{
get { return targetAddress ?? (targetAddress = ActivationAddress.GetAddress(TargetSilo, TargetGrain, TargetActivation)); }
get
{
if (targetAddress is object) return targetAddress;
if (!TargetGrain.IsDefault)
{
return targetAddress = ActivationAddress.GetAddress(TargetSilo, TargetGrain, TargetActivation);
}

return null;
}

set
{
TargetGrain = value.Grain;
Expand Down
1 change: 1 addition & 0 deletions src/Orleans.Runtime/Core/Dispatcher.cs
Expand Up @@ -671,6 +671,7 @@ internal void SendMessage(Message message, IGrainContext sendingActivation = nul
private Task AddressMessage(Message message)
{
var targetAddress = message.TargetAddress;
if (targetAddress is null) throw new InvalidOperationException("Cannot address a message with a null TargetAddress");
if (targetAddress.IsComplete) return Task.CompletedTask;

var target = new PlacementTarget(
Expand Down

0 comments on commit f2334a7

Please sign in to comment.