Skip to content

Commit

Permalink
Put 'null' on the right side of a binary expression (#5590)
Browse files Browse the repository at this point in the history
Fixes #5589.
  • Loading branch information
elachlan authored Aug 18, 2020
1 parent df64529 commit f2c4bfd
Show file tree
Hide file tree
Showing 76 changed files with 194 additions and 201 deletions.
2 changes: 1 addition & 1 deletion src/Build.UnitTests/BackEnd/MockTaskBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Task<WorkUnitResult> ExecuteTask(TargetLoggingContext targetLoggingContex
}

ProjectOnErrorInstance errorTask = task as ProjectOnErrorInstance;
if (null != errorTask)
if (errorTask != null)
{
ErrorTasks.Add(errorTask);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Build.UnitTests/BackEnd/RequestBuilder_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public Task<BuildResult> BuildTargets(ProjectLoggingContext loggingContext, Buil
return Task<BuildResult>.FromResult(result);
}

if (null != _newRequests)
if (_newRequests != null)
{
string[] projectFiles = new string[_newRequests.Length];
PropertyDictionary<ProjectPropertyInstance>[] properties = new PropertyDictionary<ProjectPropertyInstance>[_newRequests.Length];
Expand Down
2 changes: 1 addition & 1 deletion src/Build.UnitTests/Evaluation/ExpressionShredder_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ private void VerifySplitSemiColonSeparatedList(string input, params string[] exp
var actual = ExpressionShredder.SplitSemiColonSeparatedList(input);
Console.WriteLine(input);

if (null == expected)
if (expected == null)
{
// passing "null" means you expect an empty array back
expected = new string[] { };
Expand Down
16 changes: 8 additions & 8 deletions src/Build.UnitTests/FileLogger_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void BasicNoExistingFile()
}
finally
{
if (null != log) File.Delete(log);
if (log != null) File.Delete(log);
}
}

Expand All @@ -92,7 +92,7 @@ public void InvalidFile()
}
finally
{
if (null != log) File.Delete(log);
if (log != null) File.Delete(log);
}
}
);
Expand Down Expand Up @@ -121,7 +121,7 @@ public void SpecificVerbosity()
}
finally
{
if (null != log) File.Delete(log);
if (log != null) File.Delete(log);
}
}

Expand Down Expand Up @@ -194,7 +194,7 @@ public void InvalidEncoding()
}
finally
{
if (null != log) File.Delete(log);
if (log != null) File.Delete(log);
}
}
);
Expand All @@ -220,7 +220,7 @@ public void ValidEncoding()
}
finally
{
if (null != log) File.Delete(log);
if (log != null) File.Delete(log);
}
}

Expand All @@ -245,7 +245,7 @@ public void ValidEncoding2()
}
finally
{
if (null != log) File.Delete(log);
if (log != null) File.Delete(log);
}
}

Expand Down Expand Up @@ -287,7 +287,7 @@ public void BasicExistingFileNoAppend()
}
finally
{
if (null != log) File.Delete(log);
if (log != null) File.Delete(log);
}
}

Expand All @@ -308,7 +308,7 @@ public void BasicExistingFileAppend()
}
finally
{
if (null != log) File.Delete(log);
if (log != null) File.Delete(log);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Build/BackEnd/BuildManager/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ public GraphBuildResult Build(BuildParameters parameters, GraphBuildRequestData
/// </summary>
public void ShutdownAllNodes()
{
if (null == _nodeManager)
if (_nodeManager == null)
{
_nodeManager = ((IBuildComponentHost)this).GetComponent(BuildComponentType.NodeManager) as INodeManager;
}
Expand Down Expand Up @@ -1971,7 +1971,7 @@ private void PerformSchedulingActions(IEnumerable<ScheduleResponse> responses)
{
NodeInfo createdNode = _nodeManager.CreateNode(GetNodeConfiguration(), response.RequiredNodeType);

if (null != createdNode)
if (createdNode != null)
{
_noNodesActiveEvent.Reset();
_activeNodes.Add(createdNode.NodeId);
Expand Down Expand Up @@ -2142,7 +2142,7 @@ private void CheckAllSubmissionsComplete(BuildRequestDataFlags? flags)
/// </summary>
private NodeConfiguration GetNodeConfiguration()
{
if (null == _nodeConfiguration)
if (_nodeConfiguration == null)
{
// Get the remote loggers
ILoggingService loggingService = ((IBuildComponentHost)this).GetComponent(BuildComponentType.LoggingService) as ILoggingService;
Expand Down
2 changes: 1 addition & 1 deletion src/Build/BackEnd/BuildManager/BuildSubmission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private void CheckForCompletion()
{
_completionEvent.Set();

if (null != _completionCallback)
if (_completionCallback != null)
{
void Callback(object state)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ private void BuildRequestEntry_StateChanged(BuildRequestEntry entry, BuildReques
private void RaiseRequestComplete(BuildRequest request, BuildResult result)
{
RequestCompleteDelegate requestComplete = OnRequestComplete;
if (null != requestComplete)
if (requestComplete != null)
{
TraceEngine("RRC: Reporting result for request {0}({1}) (nr {2}).", request.GlobalRequestId, request.ConfigurationId, request.NodeRequestId);
requestComplete(request, result);
Expand Down Expand Up @@ -718,7 +718,7 @@ private void EvaluateRequestStates()

// This request is ready to be built
case BuildRequestEntryState.Ready:
if (null == firstReadyEntry)
if (firstReadyEntry == null)
{
firstReadyEntry = currentEntry;
}
Expand Down Expand Up @@ -747,9 +747,9 @@ private void EvaluateRequestStates()
}

// Update current engine status and start the next request, if applicable.
if (null == activeEntry)
if (activeEntry == null)
{
if (null != firstReadyEntry)
if (firstReadyEntry != null)
{
// We are now active because we have an entry which is building.
ChangeStatus(BuildRequestEngineStatus.Active);
Expand Down
2 changes: 1 addition & 1 deletion src/Build/BackEnd/Components/Caching/ResultsCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ private static bool CheckResults(BuildResult result, List<string> targets, HashS
{
if (!result.HasResultsForTarget(target) || (result[target].ResultCode == TargetResultCode.Skipped && !skippedResultsAreOK))
{
if (null != targetsMissingResults)
if (targetsMissingResults != null)
{
targetsMissingResults.Add(target);
returnValue = false;
Expand Down
22 changes: 11 additions & 11 deletions src/Build/BackEnd/Components/Communications/NodeEndpointInProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ internal static EndpointPair CreateInProcEndpoints(EndpointMode mode, IBuildComp
/// <param name="newStatus">The new status of the endpoint link.</param>
private void RaiseLinkStatusChanged(LinkStatus newStatus)
{
if (null != OnLinkStatusChanged)
if (OnLinkStatusChanged != null)
{
LinkStatusChangedDelegate linkStatusDelegate = OnLinkStatusChanged;
linkStatusDelegate(this, newStatus);
Expand Down Expand Up @@ -326,8 +326,8 @@ private void EnqueuePacket(INodePacket packet)
{
ErrorUtilities.VerifyThrowArgumentNull(packet, nameof(packet));
ErrorUtilities.VerifyThrow(_mode == EndpointMode.Asynchronous, "EndPoint mode is synchronous, should be asynchronous");
ErrorUtilities.VerifyThrow(null != _packetQueue, "packetQueue is null");
ErrorUtilities.VerifyThrow(null != _packetAvailable, "packetAvailable is null");
ErrorUtilities.VerifyThrow(_packetQueue != null, "packetQueue is null");
ErrorUtilities.VerifyThrow(_packetAvailable != null, "packetAvailable is null");

_packetQueue.Enqueue(packet);
_packetAvailable.Set();
Expand All @@ -340,10 +340,10 @@ private void InitializeAsyncPacketThread()
{
lock (_asyncDataMonitor)
{
ErrorUtilities.VerifyThrow(null == _packetPump, "packetPump != null");
ErrorUtilities.VerifyThrow(null == _packetAvailable, "packetAvailable != null");
ErrorUtilities.VerifyThrow(null == _terminatePacketPump, "terminatePacketPump != null");
ErrorUtilities.VerifyThrow(null == _packetQueue, "packetQueue != null");
ErrorUtilities.VerifyThrow(_packetPump == null, "packetPump != null");
ErrorUtilities.VerifyThrow(_packetAvailable == null, "packetAvailable != null");
ErrorUtilities.VerifyThrow(_terminatePacketPump == null, "terminatePacketPump != null");
ErrorUtilities.VerifyThrow(_packetQueue == null, "packetQueue != null");

#if FEATURE_THREAD_CULTURE
_packetPump = new Thread(PacketPumpProc);
Expand Down Expand Up @@ -377,10 +377,10 @@ private void TerminateAsyncPacketThread()
{
lock (_asyncDataMonitor)
{
ErrorUtilities.VerifyThrow(null != _packetPump, "packetPump == null");
ErrorUtilities.VerifyThrow(null != _packetAvailable, "packetAvailable == null");
ErrorUtilities.VerifyThrow(null != _terminatePacketPump, "terminatePacketPump == null");
ErrorUtilities.VerifyThrow(null != _packetQueue, "packetQueue == null");
ErrorUtilities.VerifyThrow(_packetPump != null, "packetPump == null");
ErrorUtilities.VerifyThrow(_packetAvailable != null, "packetAvailable == null");
ErrorUtilities.VerifyThrow(_terminatePacketPump != null, "terminatePacketPump == null");
ErrorUtilities.VerifyThrow(_packetQueue != null, "packetQueue == null");

_terminatePacketPump.Set();
if (!_packetPump.Join((int)new TimeSpan(0, 0, BuildParameters.EndpointShutdownTimeout).TotalMilliseconds))
Expand Down
4 changes: 1 addition & 3 deletions src/Build/BackEnd/Components/Communications/NodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ public void ShutdownConnectedNodes(bool enableReuse)
}

_nodesShutdown = true;

_inProcNodeProvider?.ShutdownConnectedNodes(enableReuse);

_outOfProcNodeProvider?.ShutdownConnectedNodes(enableReuse);
}

Expand Down Expand Up @@ -316,7 +314,7 @@ private void RemoveNodeFromMapping(int nodeId)
private int AttemptCreateNode(INodeProvider nodeProvider, NodeConfiguration nodeConfiguration)
{
// If no provider was passed in, we obviously can't create a node.
if (null == nodeProvider)
if (nodeProvider == null)
{
ErrorUtilities.ThrowInternalError("No node provider provided.");
return InvalidNodeId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void SendData(int nodeId, INodePacket packet)
ErrorUtilities.VerifyThrowArgumentOutOfRange(nodeId == _inProcNodeId, "node");
ErrorUtilities.VerifyThrowArgumentNull(packet, nameof(packet));

if (null == _inProcNode)
if (_inProcNode == null)
{
return;
}
Expand All @@ -167,7 +167,7 @@ public void SendData(int nodeId, INodePacket packet)
/// <param name="enableReuse">Flag indicating if the nodes should prepare for reuse.</param>
public void ShutdownConnectedNodes(bool enableReuse)
{
if (null != _inProcNode)
if (_inProcNode != null)
{
_inProcNodeEndpoint.SendData(new NodeBuildComplete(enableReuse));
}
Expand Down Expand Up @@ -333,8 +333,8 @@ static internal IBuildComponent CreateComponent(BuildComponentType type)
/// </summary>
private bool InstantiateNode(INodePacketFactory factory)
{
ErrorUtilities.VerifyThrow(null == _inProcNode, "In Proc node already instantiated.");
ErrorUtilities.VerifyThrow(null == _inProcNodeEndpoint, "In Proc node endpoint already instantiated.");
ErrorUtilities.VerifyThrow(_inProcNode == null, "In Proc node already instantiated.");
ErrorUtilities.VerifyThrow(_inProcNodeEndpoint == null, "In Proc node endpoint already instantiated.");

NodeEndpointInProc.EndpointPair endpoints = NodeEndpointInProc.CreateInProcEndpoints(NodeEndpointInProc.EndpointMode.Synchronous, _componentHost);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public bool CreateNode(int nodeId, INodePacketFactory factory, NodeConfiguration
Handshake hostHandshake = new Handshake(CommunicationsUtilities.GetHandshakeOptions(taskHost: false, nodeReuse: ComponentHost.BuildParameters.EnableNodeReuse, lowPriority: ComponentHost.BuildParameters.LowPriority, is64Bit: EnvironmentUtilities.Is64BitProcess));
NodeContext context = GetNode(null, commandLineArgs, nodeId, factory, hostHandshake, NodeContextTerminated);

if (null != context)
if (context != null)
{
_nodeContexts[nodeId] = context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ protected void ShutdownAllNodes(bool nodeReuse, NodeContextTerminateDelegate ter
// Attempt to connect to the process with the handshake without low priority.
Stream nodeStream = TryConnectToProcess(nodeProcess.Id, timeout, NodeProviderOutOfProc.GetHandshake(nodeReuse, false));

if (null == nodeStream)
if (nodeStream == null)
{
// If we couldn't connect attempt to connect to the process with the handshake including low priority.
nodeStream = TryConnectToProcess(nodeProcess.Id, timeout, NodeProviderOutOfProc.GetHandshake(nodeReuse, true));
}

if (null != nodeStream)
if (nodeStream != null)
{
// If we're able to connect to such a process, send a packet requesting its termination
CommunicationsUtilities.Trace("Shutting down node with pid = {0}", nodeProcess.Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ internal bool CreateNode(HandshakeOptions hostContext, INodePacketFactory factor
NodeContextTerminated
);

if (null != context)
if (context != null)
{
_nodeContexts[hostContext] = context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public void SendData(int node, INodePacket packet)
public void ShutdownConnectedNodes(bool enableReuse)
{
ErrorUtilities.VerifyThrow(!_componentShutdown, "We should never be calling ShutdownNodes after ShutdownComponent has been called");

_outOfProcTaskHostNodeProvider?.ShutdownConnectedNodes(enableReuse);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Build/BackEnd/Components/Logging/LoggingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ private void InitializeLogger(ILogger logger, IEventSource sourceForLogger)
try
{
INodeLogger nodeLogger = logger as INodeLogger;
if (null != nodeLogger)
if (nodeLogger != null)
{
nodeLogger.Initialize(sourceForLogger, _maxCPUCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ ElementLocation elementLocation

// If we didn't find a bucket that matches this item, create a new one, adding
// this item to the bucket.
if (null == matchingBucket)
if (matchingBucket == null)
{
matchingBucket = new ItemBucket(itemListsToBeBatched.Keys, itemMetadataValues, lookup, buckets.Count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ public string GetEscapedValue(string specifiedItemType, string name)
public string GetEscapedValueIfPresent(string specifiedItemType, string name)
{
string value = null;
if (null == specifiedItemType || specifiedItemType == _itemType)
if (specifiedItemType == null || specifiedItemType == _itemType)
{
// Look in the addTable
if (_addTable.TryGetValue(name, out value))
Expand All @@ -690,17 +690,17 @@ public string GetEscapedValueIfPresent(string specifiedItemType, string name)
}

// Look in the bucket table
if (null != _bucketTable)
if (_bucketTable != null)
{
value = _bucketTable.GetEscapedValueIfPresent(specifiedItemType, name);
if (null != value)
if (value != null)
{
return value;
}
}

// Look in the item definition table
if (null != _itemDefinitionTable)
if (_itemDefinitionTable != null)
{
value = _itemDefinitionTable.GetEscapedValueIfPresent(specifiedItemType, name);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Build/BackEnd/Components/RequestBuilder/RequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void BuildRequest(NodeLoggingContext loggingContext, BuildRequestEntry en
{
ErrorUtilities.VerifyThrowArgumentNull(loggingContext, nameof(loggingContext));
ErrorUtilities.VerifyThrowArgumentNull(entry, nameof(entry));
ErrorUtilities.VerifyThrow(null != _componentHost, "Host not set.");
ErrorUtilities.VerifyThrow(_componentHost != null, "Host not set.");
ErrorUtilities.VerifyThrow(_targetBuilder == null, "targetBuilder not null");
ErrorUtilities.VerifyThrow(_nodeLoggingContext == null, "nodeLoggingContext not null");
ErrorUtilities.VerifyThrow(_requestEntry == null, "requestEntry not null");
Expand Down Expand Up @@ -726,7 +726,7 @@ private async Task BuildAndReport()
}
catch (InvalidProjectFileException ex)
{
if (null != _projectLoggingContext)
if (_projectLoggingContext != null)
{
_projectLoggingContext.LogInvalidProjectFileError(ex);
}
Expand Down Expand Up @@ -764,7 +764,7 @@ private async Task BuildAndReport()
{
_blockType = BlockType.Unblocked;

if (null != thrownException)
if (thrownException != null)
{
ErrorUtilities.VerifyThrow(result == null, "Result already set when exception was thrown.");
result = new BuildResult(_requestEntry.Request, thrownException);
Expand All @@ -781,7 +781,7 @@ private async Task BuildAndReport()
/// </summary>
private void ReportResultAndCleanUp(BuildResult result)
{
if (null != _projectLoggingContext)
if (_projectLoggingContext != null)
{
try
{
Expand Down
Loading

0 comments on commit f2c4bfd

Please sign in to comment.