Skip to content

Commit 7216e84

Browse files
authored
null != x => x != null (#2751)
1 parent 6fbbb78 commit 7216e84

File tree

103 files changed

+900
-883
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+900
-883
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void ClearAllPools()
5555
foreach (KeyValuePair<DbConnectionPoolKey, DbConnectionPoolGroup> entry in connectionPoolGroups)
5656
{
5757
DbConnectionPoolGroup poolGroup = entry.Value;
58-
if (null != poolGroup)
58+
if (poolGroup != null)
5959
{
6060
poolGroup.Clear();
6161
}
@@ -69,7 +69,7 @@ public void ClearPool(DbConnection connection)
6969
using (TryEventScope.Create("<prov.DbConnectionFactory.ClearPool|API> {0}", GetObjectId(connection)))
7070
{
7171
DbConnectionPoolGroup poolGroup = GetConnectionPoolGroup(connection);
72-
if (null != poolGroup)
72+
if (poolGroup != null)
7373
{
7474
poolGroup.Clear();
7575
}
@@ -98,15 +98,15 @@ internal virtual DbConnectionPoolProviderInfo CreateConnectionPoolProviderInfo(D
9898

9999
internal DbConnectionInternal CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
100100
{
101-
Debug.Assert(null != owningConnection, "null owningConnection?");
102-
Debug.Assert(null != poolGroup, "null poolGroup?");
101+
Debug.Assert(owningConnection != null, "null owningConnection?");
102+
Debug.Assert(poolGroup != null, "null poolGroup?");
103103

104104
DbConnectionOptions connectionOptions = poolGroup.ConnectionOptions;
105105
DbConnectionPoolGroupProviderInfo poolGroupProviderInfo = poolGroup.ProviderInfo;
106106
DbConnectionPoolKey poolKey = poolGroup.PoolKey;
107107

108108
DbConnectionInternal newConnection = CreateConnection(connectionOptions, poolKey, poolGroupProviderInfo, null, owningConnection, userOptions);
109-
if (null != newConnection)
109+
if (newConnection != null)
110110
{
111111
SqlClientEventSource.Log.HardConnectRequest();
112112
newConnection.MakeNonPooledObject(owningConnection);
@@ -117,11 +117,11 @@ internal DbConnectionInternal CreateNonPooledConnection(DbConnection owningConne
117117

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

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

170-
Debug.Assert(null != owningObject, "null owningObject?");
171-
Debug.Assert(null != connectionPoolGroup, "null connectionPoolGroup?");
170+
Debug.Assert(owningObject != null, "null owningObject?");
171+
Debug.Assert(connectionPoolGroup != null, "null connectionPoolGroup?");
172172

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

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

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

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

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

208208
DbConnectionPoolGroup connectionPoolGroup;
209209
Dictionary<DbConnectionPoolKey, DbConnectionPoolGroup> connectionPoolGroups = _connectionPoolGroups;
210-
if (!connectionPoolGroups.TryGetValue(key, out connectionPoolGroup) || (connectionPoolGroup.IsDisabled && (null != connectionPoolGroup.PoolGroupOptions)))
210+
if (!connectionPoolGroups.TryGetValue(key, out connectionPoolGroup) || (connectionPoolGroup.IsDisabled && connectionPoolGroup.PoolGroupOptions != null))
211211
{
212212
// If we can't find an entry for the connection string in
213213
// our collection of pool entries, then we need to create a
@@ -238,7 +238,7 @@ internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnectionPoolKey key, D
238238
// We don't support connection pooling on Win9x
239239
if (poolOptions == null)
240240
{
241-
if (null != connectionPoolGroup)
241+
if (connectionPoolGroup != null)
242242
{
243243
// reusing existing pool option in case user originally used SetConnectionPoolOptions
244244
poolOptions = connectionPoolGroup.PoolGroupOptions;
@@ -276,8 +276,8 @@ internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnectionPoolKey key, D
276276
Debug.Assert(!connectionPoolGroup.IsDisabled, "Disabled pool entry discovered");
277277
}
278278
}
279-
Debug.Assert(null != connectionPoolGroup, "how did we not create a pool entry?");
280-
Debug.Assert(null != userConnectionOptions, "how did we not have user connection options?");
279+
Debug.Assert(connectionPoolGroup != null, "how did we not create a pool entry?");
280+
Debug.Assert(userConnectionOptions != null, "how did we not have user connection options?");
281281
}
282282
else if (userConnectionOptions == null)
283283
{
@@ -303,7 +303,7 @@ private void PruneConnectionPoolGroups(object state)
303303
DbConnectionPool[] poolsToRelease = _poolsToRelease.ToArray();
304304
foreach (DbConnectionPool pool in poolsToRelease)
305305
{
306-
if (null != pool)
306+
if (pool != null)
307307
{
308308
pool.Clear();
309309

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

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

354354
foreach (KeyValuePair<DbConnectionPoolKey, DbConnectionPoolGroup> entry in connectionPoolGroups)
355355
{
356-
if (null != entry.Value)
356+
if (entry.Value != null)
357357
{
358358
Debug.Assert(!entry.Value.IsDisabled, "Disabled pool entry discovered");
359359

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

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

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

407407
lock (_poolGroupsToRelease)

src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ internal void MakePooledConnection(DbConnectionPool connectionPool)
300300
internal void NotifyWeakReference(int message)
301301
{
302302
DbReferenceCollection referenceCollection = ReferenceCollection;
303-
if (null != referenceCollection)
303+
if (referenceCollection != null)
304304
{
305305
referenceCollection.Notify(message);
306306
}
@@ -418,7 +418,7 @@ internal void PostPop(DbConnection newOwner)
418418
SqlClientEventSource.Log.TryPoolerTraceEvent("<prov.DbConnectionInternal.PostPop|RES|CPOOL> {0}, Preparing to pop from pool, owning connection {1}, pooledCount={2}", ObjectID, 0, _pooledCount);
419419

420420
//3 // The following tests are retail assertions of things we can't allow to happen.
421-
if (null != Pool)
421+
if (Pool != null)
422422
{
423423
if (0 != _pooledCount)
424424
{
@@ -434,7 +434,7 @@ internal void PostPop(DbConnection newOwner)
434434
internal void RemoveWeakReference(object value)
435435
{
436436
DbReferenceCollection referenceCollection = ReferenceCollection;
437-
if (null != referenceCollection)
437+
if (referenceCollection != null)
438438
{
439439
referenceCollection.Remove(value);
440440
}

src/Microsoft.Data.SqlClient/netcore/src/Interop/SNINativeMethodWrapper.Windows.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,10 @@ internal static uint SNIWritePacket(SNIHandle pConn, SNIPacket packet, bool sync
505505
private static void MarshalConsumerInfo(ConsumerInfo consumerInfo, ref Sni_Consumer_Info native_consumerInfo)
506506
{
507507
native_consumerInfo.DefaultUserDataLength = consumerInfo.defaultBufferSize;
508-
native_consumerInfo.fnReadComp = null != consumerInfo.readDelegate
508+
native_consumerInfo.fnReadComp = consumerInfo.readDelegate != null
509509
? Marshal.GetFunctionPointerForDelegate(consumerInfo.readDelegate)
510510
: IntPtr.Zero;
511-
native_consumerInfo.fnWriteComp = null != consumerInfo.writeDelegate
511+
native_consumerInfo.fnWriteComp = consumerInfo.writeDelegate != null
512512
? Marshal.GetFunctionPointerForDelegate(consumerInfo.writeDelegate)
513513
: IntPtr.Zero;
514514
native_consumerInfo.ConsumerKey = consumerInfo.key;

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/Common/DbConnectionOptions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal string ExpandAttachDbFileName(string replacementValue)
1515
int copyPosition = 0;
1616

1717
StringBuilder builder = new(_usersConnectionString.Length);
18-
for (NameValuePair current = _keyChain; null != current; current = current.Next)
18+
for (NameValuePair current = _keyChain; current != null; current = current.Next)
1919
{
2020
if (string.Equals(current.Name, DbConnectionStringKeywords.AttachDBFilename, StringComparison.InvariantCultureIgnoreCase))
2121
{
@@ -38,12 +38,12 @@ internal string ExpandAttachDbFileName(string replacementValue)
3838
internal static string ExpandDataDirectory(string keyword, string value)
3939
{
4040
string fullPath = null;
41-
if ((null != value) && value.StartsWith(DataDirectory, StringComparison.OrdinalIgnoreCase))
41+
if (value != null && value.StartsWith(DataDirectory, StringComparison.OrdinalIgnoreCase))
4242
{
4343
// find the replacement path
4444
object rootFolderObject = AppDomain.CurrentDomain.GetData("DataDirectory");
4545
var rootFolderPath = (rootFolderObject as string);
46-
if ((null != rootFolderObject) && rootFolderPath == null)
46+
if (rootFolderObject != null && rootFolderPath == null)
4747
{
4848
throw ADP.InvalidDataDirectory();
4949
}

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal abstract partial class DbConnectionFactory
2020

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

2525
DbConnectionPoolGroup poolGroup;
2626
DbConnectionPool connectionPool;

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ protected internal Transaction EnlistedTransaction
3737
set
3838
{
3939
Transaction currentEnlistedTransaction = _enlistedTransaction;
40-
if ((currentEnlistedTransaction == null && (null != value))
41-
|| ((null != currentEnlistedTransaction) && !currentEnlistedTransaction.Equals(value)))
40+
if ((currentEnlistedTransaction == null && value != null)
41+
|| (currentEnlistedTransaction != null && !currentEnlistedTransaction.Equals(value)))
4242
{ // WebData 20000024
4343

4444
// Pay attention to the order here:
@@ -53,7 +53,7 @@ protected internal Transaction EnlistedTransaction
5353
Transaction previousTransactionClone = null;
5454
try
5555
{
56-
if (null != value)
56+
if (value != null)
5757
{
5858
valueClone = value.Clone();
5959
}
@@ -88,12 +88,12 @@ protected internal Transaction EnlistedTransaction
8888
// we really need to dispose our clones; they may have
8989
// native resources and GC may not happen soon enough.
9090
// VSDevDiv 479564: don't dispose if still holding reference in _enlistedTransaction
91-
if (null != previousTransactionClone &&
91+
if (previousTransactionClone != null &&
9292
!object.ReferenceEquals(previousTransactionClone, _enlistedTransaction))
9393
{
9494
previousTransactionClone.Dispose();
9595
}
96-
if (null != valueClone && !object.ReferenceEquals(valueClone, _enlistedTransaction))
96+
if (valueClone != null && !object.ReferenceEquals(valueClone, _enlistedTransaction))
9797
{
9898
valueClone.Dispose();
9999
}
@@ -104,7 +104,7 @@ protected internal Transaction EnlistedTransaction
104104
// against multiple concurrent calls to enlist, which really
105105
// isn't supported anyway.
106106

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

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

470470
DbConnectionPool pool = Pool;
471-
if (null != pool)
471+
if (pool != null)
472472
{
473473
pool.TransactionEnded(transaction, this);
474474
}

0 commit comments

Comments
 (0)