Skip to content

Commit d87acf5

Browse files
authored
simplify some null checks (#7659)
1 parent 82b91de commit d87acf5

File tree

19 files changed

+49
-136
lines changed

19 files changed

+49
-136
lines changed

src/contrib/cluster/Akka.Cluster.Sharding.Tests.MultiNode/AsyncWriteProxyEx.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,8 @@ public sealed class SetStore
6565
/// <exception cref="ArgumentNullException">
6666
/// This exception is thrown when the specified <paramref name="store"/> is undefined.
6767
/// </exception>
68-
public SetStore(IActorRef store)
69-
{
70-
if (store == null)
71-
throw new ArgumentNullException(nameof(store), "SetStore requires non-null reference to store actor");
72-
73-
Store = store;
74-
}
68+
public SetStore(IActorRef store) =>
69+
Store = store ?? throw new ArgumentNullException(nameof(store), "SetStore requires non-null reference to store actor");
7570

7671
/// <summary>
7772
/// TBD

src/contrib/cluster/Akka.Cluster.Sharding/ClusterShardingGuardian.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ public Start(
9595
object handOffStopMessage)
9696
{
9797
if (string.IsNullOrEmpty(typeName)) throw new ArgumentNullException(nameof(typeName), "ClusterSharding start requires type name to be provided");
98-
if (entityProps == null) throw new ArgumentNullException(nameof(entityProps), $"ClusterSharding start requires Props for [{typeName}] to be provided");
9998

10099
TypeName = typeName;
101-
EntityProps = entityProps;
100+
EntityProps = entityProps ?? throw new ArgumentNullException(nameof(entityProps), $"ClusterSharding start requires Props for [{typeName}] to be provided");
102101
Settings = settings;
103102
MessageExtractor = extractor;
104103
AllocationStrategy = allocationStrategy;

src/contrib/cluster/Akka.DistributedData/ORDictionary.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,7 @@ internal sealed class PutDeltaOperation : AtomicDeltaOperation, ORDictionary.IPu
488488

489489
public PutDeltaOperation(ORSet<TKey>.IDeltaOperation underlying, TKey key, TValue value)
490490
{
491-
if (underlying == null) throw new ArgumentNullException(nameof(underlying));
492-
493-
Underlying = underlying;
491+
Underlying = underlying ?? throw new ArgumentNullException(nameof(underlying));
494492
Key = key;
495493
Value = value;
496494
}

src/core/Akka.Cluster/SplitBrainResolver.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,8 @@ public static Actor.Props Props(TimeSpan stableAfter, ISplitBrainStrategy strate
257257

258258
public SplitBrainDecider(TimeSpan stableAfter, ISplitBrainStrategy strategy, Cluster cluster)
259259
{
260-
if (strategy == null) throw new ArgumentNullException(nameof(strategy));
261-
262260
_stabilityTimeout = stableAfter;
263-
_strategy = strategy;
261+
_strategy = strategy ?? throw new ArgumentNullException(nameof(strategy));
264262
_cluster = cluster;
265263
}
266264

src/core/Akka.Persistence/AtLeastOnceDeliverySemantic.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@ public sealed class AtLeastOnceDeliverySnapshot : IMessage, IEquatable<AtLeastOn
3737
/// </exception>
3838
public AtLeastOnceDeliverySnapshot(long currentDeliveryId, UnconfirmedDelivery[] unconfirmedDeliveries)
3939
{
40-
if (unconfirmedDeliveries == null)
41-
throw new ArgumentNullException(nameof(unconfirmedDeliveries),
42-
"AtLeastOnceDeliverySnapshot expects not null array of unconfirmed deliveries");
43-
4440
CurrentDeliveryId = currentDeliveryId;
45-
UnconfirmedDeliveries = unconfirmedDeliveries;
41+
UnconfirmedDeliveries = unconfirmedDeliveries ?? throw new ArgumentNullException(nameof(unconfirmedDeliveries),
42+
"AtLeastOnceDeliverySnapshot expects not null array of unconfirmed deliveries");
4643
}
4744

4845
/// <summary>
@@ -97,14 +94,9 @@ public sealed class UnconfirmedWarning : IEquatable<UnconfirmedWarning>
9794
/// <exception cref="ArgumentNullException">
9895
/// This exception is thrown when the specified <paramref name="unconfirmedDeliveries"/> array is undefined.
9996
/// </exception>
100-
public UnconfirmedWarning(UnconfirmedDelivery[] unconfirmedDeliveries)
101-
{
102-
if (unconfirmedDeliveries == null)
103-
throw new ArgumentNullException(nameof(unconfirmedDeliveries),
104-
"UnconfirmedWarning expects not null array of unconfirmed deliveries");
105-
106-
UnconfirmedDeliveries = unconfirmedDeliveries;
107-
}
97+
public UnconfirmedWarning(UnconfirmedDelivery[] unconfirmedDeliveries) =>
98+
UnconfirmedDeliveries = unconfirmedDeliveries ?? throw new ArgumentNullException(nameof(unconfirmedDeliveries),
99+
"UnconfirmedWarning expects not null array of unconfirmed deliveries");
108100

109101
/// <summary>
110102
/// TBD

src/core/Akka.Persistence/Journal/AsyncWriteProxy.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,8 @@ public sealed class ReplayFailure
9494
/// <exception cref="System.ArgumentNullException">
9595
/// This exception is thrown when the specified <paramref name="cause"/> is undefined.
9696
/// </exception>
97-
public ReplayFailure(Exception cause)
98-
{
99-
if (cause == null)
100-
throw new ArgumentNullException(nameof(cause), "AsyncWriteTarget.ReplayFailure cause exception cannot be null");
101-
102-
Cause = cause;
103-
}
97+
public ReplayFailure(Exception cause) =>
98+
Cause = cause ?? throw new ArgumentNullException(nameof(cause), "AsyncWriteTarget.ReplayFailure cause exception cannot be null");
10499

105100
/// <summary>
106101
/// The cause of the failure

src/core/Akka.Persistence/JournalProtocol.cs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ public sealed class DeleteMessagesFailure : IEquatable<DeleteMessagesFailure>, I
7878
/// </exception>
7979
public DeleteMessagesFailure(Exception cause, long toSequenceNr)
8080
{
81-
if (cause == null)
82-
throw new ArgumentNullException(nameof(cause), "DeleteMessagesFailure cause exception cannot be null");
83-
84-
Cause = cause;
81+
Cause = cause ?? throw new ArgumentNullException(nameof(cause), "DeleteMessagesFailure cause exception cannot be null");
8582
ToSequenceNr = toSequenceNr;
8683
}
8784

@@ -373,11 +370,8 @@ public sealed class WriteMessageRejected : IJournalResponse, INoSerializationVer
373370
/// </exception>
374371
public WriteMessageRejected(IPersistentRepresentation persistent, Exception cause, int actorInstanceId)
375372
{
376-
if (cause == null)
377-
throw new ArgumentNullException(nameof(cause), "WriteMessageRejected cause exception cannot be null");
378-
379373
Persistent = persistent;
380-
Cause = cause;
374+
Cause = cause ?? throw new ArgumentNullException(nameof(cause), "WriteMessageRejected cause exception cannot be null");
381375
ActorInstanceId = actorInstanceId;
382376
}
383377

@@ -440,11 +434,8 @@ public sealed class WriteMessageFailure : IJournalResponse, INoSerializationVeri
440434
/// </exception>
441435
public WriteMessageFailure(IPersistentRepresentation persistent, Exception cause, int actorInstanceId)
442436
{
443-
if (cause == null)
444-
throw new ArgumentNullException(nameof(cause), "WriteMessageFailure cause exception cannot be null");
445-
446437
Persistent = persistent;
447-
Cause = cause;
438+
Cause = cause ?? throw new ArgumentNullException(nameof(cause), "WriteMessageFailure cause exception cannot be null");
448439
ActorInstanceId = actorInstanceId;
449440
}
450441

@@ -705,20 +696,14 @@ public sealed class ReplayMessagesFailure : IJournalResponse, IDeadLetterSuppres
705696
/// <exception cref="ArgumentNullException">
706697
/// This exception is thrown when the specified <paramref name="cause"/> is undefined.
707698
/// </exception>
708-
public ReplayMessagesFailure(Exception cause)
709-
{
710-
if (cause == null)
711-
throw new ArgumentNullException(nameof(cause), "ReplayMessagesFailure cause exception cannot be null");
712-
713-
Cause = cause;
714-
}
699+
public ReplayMessagesFailure(Exception cause) =>
700+
Cause = cause ?? throw new ArgumentNullException(nameof(cause), "ReplayMessagesFailure cause exception cannot be null");
715701

716702
/// <summary>
717703
/// The cause of the failure
718704
/// </summary>
719705
public Exception Cause { get; }
720706

721-
722707
public bool Equals(ReplayMessagesFailure other)
723708
{
724709
if (ReferenceEquals(other, null)) return false;
@@ -727,13 +712,10 @@ public bool Equals(ReplayMessagesFailure other)
727712
return Equals(Cause, other.Cause);
728713
}
729714

730-
731715
public override bool Equals(object obj) => Equals(obj as ReplayMessagesFailure);
732716

733-
734717
public override int GetHashCode() => Cause.GetHashCode();
735718

736-
737719
public override string ToString() => $"ReplayMessagesFailure<cause: {Cause}>";
738720
}
739721
}

src/core/Akka.Persistence/SnapshotProtocol.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -793,10 +793,7 @@ public sealed class SaveSnapshot : ISnapshotRequest, IEquatable<SaveSnapshot>
793793
/// </exception>
794794
public SaveSnapshot(SnapshotMetadata metadata, object snapshot)
795795
{
796-
if (metadata == null)
797-
throw new ArgumentNullException(nameof(metadata), "SaveSnapshot requires SnapshotMetadata to be provided");
798-
799-
Metadata = metadata;
796+
Metadata = metadata ?? throw new ArgumentNullException(nameof(metadata), "SaveSnapshot requires SnapshotMetadata to be provided");
800797
Snapshot = snapshot;
801798
}
802799

@@ -848,13 +845,8 @@ public sealed class DeleteSnapshot : ISnapshotRequest, IEquatable<DeleteSnapshot
848845
/// <exception cref="ArgumentNullException">
849846
/// This exception is thrown when the specified <paramref name="metadata"/> is undefined.
850847
/// </exception>
851-
public DeleteSnapshot(SnapshotMetadata metadata)
852-
{
853-
if (metadata == null)
854-
throw new ArgumentNullException(nameof(metadata), "DeleteSnapshot requires SnapshotMetadata to be provided");
855-
856-
Metadata = metadata;
857-
}
848+
public DeleteSnapshot(SnapshotMetadata metadata) =>
849+
Metadata = metadata ?? throw new ArgumentNullException(nameof(metadata), "DeleteSnapshot requires SnapshotMetadata to be provided");
858850

859851
/// <summary>
860852
/// Snapshot metadata.

src/core/Akka.Streams/Actors/ActorPublisher.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -666,11 +666,8 @@ public sealed class ActorPublisherImpl<T> : IPublisher<T>
666666
/// <exception cref="ArgumentNullException">
667667
/// This exception is thrown when the specified <paramref name="ref"/> is undefined.
668668
/// </exception>
669-
public ActorPublisherImpl(IActorRef @ref)
670-
{
671-
if(@ref == null) throw new ArgumentNullException(nameof(@ref), "ActorPublisherImpl requires IActorRef to be defined");
672-
_ref = @ref;
673-
}
669+
public ActorPublisherImpl(IActorRef @ref) =>
670+
_ref = @ref ?? throw new ArgumentNullException(nameof(@ref), "ActorPublisherImpl requires IActorRef to be defined");
674671

675672
/// <summary>
676673
/// TBD
@@ -700,11 +697,8 @@ public sealed class ActorPublisherSubscription : ISubscription
700697
/// <exception cref="ArgumentNullException">
701698
/// This exception is thrown when the specified <paramref name="ref"/> is undefined.
702699
/// </exception>
703-
public ActorPublisherSubscription(IActorRef @ref)
704-
{
705-
if (@ref == null) throw new ArgumentNullException(nameof(@ref), "ActorPublisherSubscription requires IActorRef to be defined");
706-
_ref = @ref;
707-
}
700+
public ActorPublisherSubscription(IActorRef @ref) =>
701+
_ref = @ref ?? throw new ArgumentNullException(nameof(@ref), "ActorPublisherSubscription requires IActorRef to be defined");
708702

709703
/// <summary>
710704
/// TBD

src/core/Akka.Streams/Actors/ActorSubscriber.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,8 @@ public sealed class ActorSubscriberImpl<T> : ISubscriber<T>
319319
/// <exception cref="ArgumentNullException">
320320
/// This exception is thrown when the specified <paramref name="impl"/> is undefined.
321321
/// </exception>
322-
public ActorSubscriberImpl(IActorRef impl)
323-
{
324-
if (impl == null) throw new ArgumentNullException(nameof(impl), "ActorSubscriberImpl requires actor impl to be defined");
325-
_impl = impl;
326-
}
322+
public ActorSubscriberImpl(IActorRef impl) =>
323+
_impl = impl ?? throw new ArgumentNullException(nameof(impl), "ActorSubscriberImpl requires actor impl to be defined");
327324

328325
/// <summary>
329326
/// TBD

0 commit comments

Comments
 (0)