Skip to content

Commit

Permalink
null != x => x != null (#2751)
Browse files Browse the repository at this point in the history
  • Loading branch information
benrr101 authored Aug 9, 2024
1 parent 6fbbb78 commit 7216e84
Show file tree
Hide file tree
Showing 103 changed files with 900 additions and 883 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void ClearAllPools()
foreach (KeyValuePair<DbConnectionPoolKey, DbConnectionPoolGroup> entry in connectionPoolGroups)
{
DbConnectionPoolGroup poolGroup = entry.Value;
if (null != poolGroup)
if (poolGroup != null)
{
poolGroup.Clear();
}
Expand All @@ -69,7 +69,7 @@ public void ClearPool(DbConnection connection)
using (TryEventScope.Create("<prov.DbConnectionFactory.ClearPool|API> {0}", GetObjectId(connection)))
{
DbConnectionPoolGroup poolGroup = GetConnectionPoolGroup(connection);
if (null != poolGroup)
if (poolGroup != null)
{
poolGroup.Clear();
}
Expand Down Expand Up @@ -98,15 +98,15 @@ internal virtual DbConnectionPoolProviderInfo CreateConnectionPoolProviderInfo(D

internal DbConnectionInternal CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
{
Debug.Assert(null != owningConnection, "null owningConnection?");
Debug.Assert(null != poolGroup, "null poolGroup?");
Debug.Assert(owningConnection != null, "null owningConnection?");
Debug.Assert(poolGroup != null, "null poolGroup?");

DbConnectionOptions connectionOptions = poolGroup.ConnectionOptions;
DbConnectionPoolGroupProviderInfo poolGroupProviderInfo = poolGroup.ProviderInfo;
DbConnectionPoolKey poolKey = poolGroup.PoolKey;

DbConnectionInternal newConnection = CreateConnection(connectionOptions, poolKey, poolGroupProviderInfo, null, owningConnection, userOptions);
if (null != newConnection)
if (newConnection != null)
{
SqlClientEventSource.Log.HardConnectRequest();
newConnection.MakeNonPooledObject(owningConnection);
Expand All @@ -117,11 +117,11 @@ internal DbConnectionInternal CreateNonPooledConnection(DbConnection owningConne

internal DbConnectionInternal CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
{
Debug.Assert(null != pool, "null pool?");
Debug.Assert(pool != null, "null pool?");
DbConnectionPoolGroupProviderInfo poolGroupProviderInfo = pool.PoolGroup.ProviderInfo;

DbConnectionInternal newConnection = CreateConnection(options, poolKey, poolGroupProviderInfo, pool, owningObject, userOptions);
if (null != newConnection)
if (newConnection != null)
{
SqlClientEventSource.Log.HardConnectRequest();
newConnection.MakePooledConnection(pool);
Expand Down Expand Up @@ -167,8 +167,8 @@ private DbConnectionPool GetConnectionPool(DbConnection owningObject, DbConnecti
{
// if poolgroup is disabled, it will be replaced with a new entry

Debug.Assert(null != owningObject, "null owningObject?");
Debug.Assert(null != connectionPoolGroup, "null connectionPoolGroup?");
Debug.Assert(owningObject != null, "null owningObject?");
Debug.Assert(connectionPoolGroup != null, "null connectionPoolGroup?");

// It is possible that while the outer connection object has
// been sitting around in a closed and unused state in some long
Expand All @@ -179,7 +179,7 @@ private DbConnectionPool GetConnectionPool(DbConnection owningObject, DbConnecti
// re-create the pool entry whenever it's disabled.

// however, don't rebuild connectionOptions if no pooling is involved - let new connections do that work
if (connectionPoolGroup.IsDisabled && (null != connectionPoolGroup.PoolGroupOptions))
if (connectionPoolGroup.IsDisabled && connectionPoolGroup.PoolGroupOptions != null)
{
SqlClientEventSource.Log.TryTraceEvent("<prov.DbConnectionFactory.GetConnectionPool|RES|INFO|CPOOL> {0}, DisabledPoolGroup={1}", ObjectID, connectionPoolGroup?.ObjectID);

Expand All @@ -188,10 +188,10 @@ private DbConnectionPool GetConnectionPool(DbConnection owningObject, DbConnecti

// get the string to hash on again
DbConnectionOptions connectionOptions = connectionPoolGroup.ConnectionOptions;
Debug.Assert(null != connectionOptions, "prevent expansion of connectionString");
Debug.Assert(connectionOptions != null, "prevent expansion of connectionString");

connectionPoolGroup = GetConnectionPoolGroup(connectionPoolGroup.PoolKey, poolOptions, ref connectionOptions);
Debug.Assert(null != connectionPoolGroup, "null connectionPoolGroup?");
Debug.Assert(connectionPoolGroup != null, "null connectionPoolGroup?");
SetConnectionPoolGroup(owningObject, connectionPoolGroup);
}
DbConnectionPool connectionPool = connectionPoolGroup.GetConnectionPool(this);
Expand All @@ -207,7 +207,7 @@ internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnectionPoolKey key, D

DbConnectionPoolGroup connectionPoolGroup;
Dictionary<DbConnectionPoolKey, DbConnectionPoolGroup> connectionPoolGroups = _connectionPoolGroups;
if (!connectionPoolGroups.TryGetValue(key, out connectionPoolGroup) || (connectionPoolGroup.IsDisabled && (null != connectionPoolGroup.PoolGroupOptions)))
if (!connectionPoolGroups.TryGetValue(key, out connectionPoolGroup) || (connectionPoolGroup.IsDisabled && connectionPoolGroup.PoolGroupOptions != null))
{
// If we can't find an entry for the connection string in
// our collection of pool entries, then we need to create a
Expand Down Expand Up @@ -238,7 +238,7 @@ internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnectionPoolKey key, D
// We don't support connection pooling on Win9x
if (poolOptions == null)
{
if (null != connectionPoolGroup)
if (connectionPoolGroup != null)
{
// reusing existing pool option in case user originally used SetConnectionPoolOptions
poolOptions = connectionPoolGroup.PoolGroupOptions;
Expand Down Expand Up @@ -276,8 +276,8 @@ internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnectionPoolKey key, D
Debug.Assert(!connectionPoolGroup.IsDisabled, "Disabled pool entry discovered");
}
}
Debug.Assert(null != connectionPoolGroup, "how did we not create a pool entry?");
Debug.Assert(null != userConnectionOptions, "how did we not have user connection options?");
Debug.Assert(connectionPoolGroup != null, "how did we not create a pool entry?");
Debug.Assert(userConnectionOptions != null, "how did we not have user connection options?");
}
else if (userConnectionOptions == null)
{
Expand All @@ -303,7 +303,7 @@ private void PruneConnectionPoolGroups(object state)
DbConnectionPool[] poolsToRelease = _poolsToRelease.ToArray();
foreach (DbConnectionPool pool in poolsToRelease)
{
if (null != pool)
if (pool != null)
{
pool.Clear();

Expand All @@ -328,7 +328,7 @@ private void PruneConnectionPoolGroups(object state)
DbConnectionPoolGroup[] poolGroupsToRelease = _poolGroupsToRelease.ToArray();
foreach (DbConnectionPoolGroup poolGroup in poolGroupsToRelease)
{
if (null != poolGroup)
if (poolGroup != null)
{
int poolsLeft = poolGroup.Clear(); // may add entries to _poolsToRelease

Expand All @@ -353,7 +353,7 @@ private void PruneConnectionPoolGroups(object state)

foreach (KeyValuePair<DbConnectionPoolKey, DbConnectionPoolGroup> entry in connectionPoolGroups)
{
if (null != entry.Value)
if (entry.Value != null)
{
Debug.Assert(!entry.Value.IsDisabled, "Disabled pool entry discovered");

Expand All @@ -380,7 +380,7 @@ internal void QueuePoolForRelease(DbConnectionPool pool, bool clearing)
// Queue the pool up for release -- we'll clear it out and dispose
// of it as the last part of the pruning timer callback so we don't
// do it with the pool entry or the pool collection locked.
Debug.Assert(null != pool, "null pool?");
Debug.Assert(pool != null, "null pool?");

// set the pool to the shutdown state to force all active
// connections to be automatically disposed when they
Expand All @@ -401,7 +401,7 @@ internal void QueuePoolForRelease(DbConnectionPool pool, bool clearing)

internal void QueuePoolGroupForRelease(DbConnectionPoolGroup poolGroup)
{
Debug.Assert(null != poolGroup, "null poolGroup?");
Debug.Assert(poolGroup != null, "null poolGroup?");
SqlClientEventSource.Log.TryTraceEvent("<prov.DbConnectionFactory.QueuePoolGroupForRelease|RES|INFO|CPOOL> {0}, poolGroup={1}", ObjectID, poolGroup.ObjectID);

lock (_poolGroupsToRelease)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ internal void MakePooledConnection(DbConnectionPool connectionPool)
internal void NotifyWeakReference(int message)
{
DbReferenceCollection referenceCollection = ReferenceCollection;
if (null != referenceCollection)
if (referenceCollection != null)
{
referenceCollection.Notify(message);
}
Expand Down Expand Up @@ -418,7 +418,7 @@ internal void PostPop(DbConnection newOwner)
SqlClientEventSource.Log.TryPoolerTraceEvent("<prov.DbConnectionInternal.PostPop|RES|CPOOL> {0}, Preparing to pop from pool, owning connection {1}, pooledCount={2}", ObjectID, 0, _pooledCount);

//3 // The following tests are retail assertions of things we can't allow to happen.
if (null != Pool)
if (Pool != null)
{
if (0 != _pooledCount)
{
Expand All @@ -434,7 +434,7 @@ internal void PostPop(DbConnection newOwner)
internal void RemoveWeakReference(object value)
{
DbReferenceCollection referenceCollection = ReferenceCollection;
if (null != referenceCollection)
if (referenceCollection != null)
{
referenceCollection.Remove(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,10 @@ internal static uint SNIWritePacket(SNIHandle pConn, SNIPacket packet, bool sync
private static void MarshalConsumerInfo(ConsumerInfo consumerInfo, ref Sni_Consumer_Info native_consumerInfo)
{
native_consumerInfo.DefaultUserDataLength = consumerInfo.defaultBufferSize;
native_consumerInfo.fnReadComp = null != consumerInfo.readDelegate
native_consumerInfo.fnReadComp = consumerInfo.readDelegate != null
? Marshal.GetFunctionPointerForDelegate(consumerInfo.readDelegate)
: IntPtr.Zero;
native_consumerInfo.fnWriteComp = null != consumerInfo.writeDelegate
native_consumerInfo.fnWriteComp = consumerInfo.writeDelegate != null
? Marshal.GetFunctionPointerForDelegate(consumerInfo.writeDelegate)
: IntPtr.Zero;
native_consumerInfo.ConsumerKey = consumerInfo.key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal string ExpandAttachDbFileName(string replacementValue)
int copyPosition = 0;

StringBuilder builder = new(_usersConnectionString.Length);
for (NameValuePair current = _keyChain; null != current; current = current.Next)
for (NameValuePair current = _keyChain; current != null; current = current.Next)
{
if (string.Equals(current.Name, DbConnectionStringKeywords.AttachDBFilename, StringComparison.InvariantCultureIgnoreCase))
{
Expand All @@ -38,12 +38,12 @@ internal string ExpandAttachDbFileName(string replacementValue)
internal static string ExpandDataDirectory(string keyword, string value)
{
string fullPath = null;
if ((null != value) && value.StartsWith(DataDirectory, StringComparison.OrdinalIgnoreCase))
if (value != null && value.StartsWith(DataDirectory, StringComparison.OrdinalIgnoreCase))
{
// find the replacement path
object rootFolderObject = AppDomain.CurrentDomain.GetData("DataDirectory");
var rootFolderPath = (rootFolderObject as string);
if ((null != rootFolderObject) && rootFolderPath == null)
if (rootFolderObject != null && rootFolderPath == null)
{
throw ADP.InvalidDataDirectory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal abstract partial class DbConnectionFactory

internal bool TryGetConnection(DbConnection owningConnection, TaskCompletionSource<DbConnectionInternal> retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, out DbConnectionInternal connection)
{
Debug.Assert(null != owningConnection, "null owningConnection?");
Debug.Assert(owningConnection != null, "null owningConnection?");

DbConnectionPoolGroup poolGroup;
DbConnectionPool connectionPool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ protected internal Transaction EnlistedTransaction
set
{
Transaction currentEnlistedTransaction = _enlistedTransaction;
if ((currentEnlistedTransaction == null && (null != value))
|| ((null != currentEnlistedTransaction) && !currentEnlistedTransaction.Equals(value)))
if ((currentEnlistedTransaction == null && value != null)
|| (currentEnlistedTransaction != null && !currentEnlistedTransaction.Equals(value)))
{ // WebData 20000024

// Pay attention to the order here:
Expand All @@ -53,7 +53,7 @@ protected internal Transaction EnlistedTransaction
Transaction previousTransactionClone = null;
try
{
if (null != value)
if (value != null)
{
valueClone = value.Clone();
}
Expand Down Expand Up @@ -88,12 +88,12 @@ protected internal Transaction EnlistedTransaction
// we really need to dispose our clones; they may have
// native resources and GC may not happen soon enough.
// VSDevDiv 479564: don't dispose if still holding reference in _enlistedTransaction
if (null != previousTransactionClone &&
if (previousTransactionClone != null &&
!object.ReferenceEquals(previousTransactionClone, _enlistedTransaction))
{
previousTransactionClone.Dispose();
}
if (null != valueClone && !object.ReferenceEquals(valueClone, _enlistedTransaction))
if (valueClone != null && !object.ReferenceEquals(valueClone, _enlistedTransaction))
{
valueClone.Dispose();
}
Expand All @@ -104,7 +104,7 @@ protected internal Transaction EnlistedTransaction
// against multiple concurrent calls to enlist, which really
// isn't supported anyway.

if (null != value)
if (value != null)
{
SqlClientEventSource.Log.TryPoolerTraceEvent("<prov.DbConnectionInternal.set_EnlistedTransaction|RES|CPOOL> {0}, Transaction {1}, Enlisting.", ObjectID, value.GetHashCode());
TransactionOutcomeEnlist(value);
Expand Down Expand Up @@ -251,7 +251,7 @@ internal virtual void CloseConnection(DbConnection owningObject, DbConnectionFac
// if the DbConnectionInternal derived class needs to close the connection it should
// delegate to the DbConnection if one exists or directly call dispose
// DbConnection owningObject = (DbConnection)Owner;
// if (null != owningObject) {
// if (owningObject != null) {
// owningObject.Close(); // force the closed state on the outer object.
// }
// else {
Expand All @@ -261,8 +261,8 @@ internal virtual void CloseConnection(DbConnection owningObject, DbConnectionFac
////////////////////////////////////////////////////////////////
// DON'T MESS WITH THIS CODE UNLESS YOU KNOW WHAT YOU'RE DOING!
////////////////////////////////////////////////////////////////
Debug.Assert(null != owningObject, "null owningObject");
Debug.Assert(null != connectionFactory, "null connectionFactory");
Debug.Assert(owningObject != null, "null owningObject");
Debug.Assert(connectionFactory != null, "null connectionFactory");
SqlClientEventSource.Log.TryPoolerTraceEvent("<prov.DbConnectionInternal.CloseConnection|RES|CPOOL> {0} Closing.", ObjectID);

// if an exception occurs after the state change but before the try block
Expand All @@ -288,7 +288,7 @@ internal virtual void CloseConnection(DbConnection owningObject, DbConnectionFac
// The singleton closed classes won't have owners and
// connection pools, and we won't want to put them back
// into the pool.
if (null != connectionPool)
if (connectionPool != null)
{
connectionPool.PutObject(this, owningObject); // PutObject calls Deactivate for us...
// NOTE: Before we leave the PutObject call, another
Expand Down Expand Up @@ -468,7 +468,7 @@ internal void CleanupConnectionOnTransactionCompletion(Transaction transaction)
DetachTransaction(transaction, false);

DbConnectionPool pool = Pool;
if (null != pool)
if (pool != null)
{
pool.TransactionEnded(transaction, this);
}
Expand Down
Loading

0 comments on commit 7216e84

Please sign in to comment.