Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Cleanup | null == x to x == null #2749

Merged
merged 2 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ byte[] DecryptEncryptionKey()
byte[] message = new byte[encryptedColumnEncryptionKey.Length - signatureLength];
Buffer.BlockCopy(encryptedColumnEncryptionKey, 0, message, 0, encryptedColumnEncryptionKey.Length - signatureLength);

if (null == message)
if (message == null)
{
throw ADP.NullHashFound();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal static void ValidateNotNullOrWhitespaceForEach(string[] parameters, str
internal static void ValidateEncryptionAlgorithm(string encryptionAlgorithm, bool isSystemOp)
{
// This validates that the encryption algorithm is RSA_OAEP
if (null == encryptionAlgorithm)
if (encryptionAlgorithm == null)
{
throw ADP.NullAlgorithm(isSystemOp);
}
Expand Down Expand Up @@ -124,8 +124,9 @@ internal static ArgumentException InvalidSignatureTemplate(string masterKeyPath)

internal static ArgumentException InvalidAKVPath(string masterKeyPath, bool isSystemOp)
{
string errorMessage = null == masterKeyPath ? Strings.NullAkvPath
: string.Format(CultureInfo.InvariantCulture, Strings.InvalidAkvPathTemplate, masterKeyPath);
string errorMessage = masterKeyPath == null
? Strings.NullAkvPath
: string.Format(CultureInfo.InvariantCulture, Strings.InvalidAkvPathTemplate, masterKeyPath);
if (isSystemOp)
{
return new ArgumentNullException(Constants.AeParamMasterKeyPath, errorMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ internal override bool TryOpenConnection(DbConnection outerConnection, DbConnect
// we are completing an asynchronous open
Debug.Assert(retry.Task.Status == TaskStatus.RanToCompletion, "retry task must be completed successfully");
DbConnectionInternal openConnection = retry.Task.Result;
if (null == openConnection)
if (openConnection == null)
{
connectionFactory.SetInnerConnectionTo(outerConnection, this);
throw ADP.InternalConnectionError(ADP.ConnectionError.GetConnectionReturnsNull);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnectionPoolKey key, D
// new pool entry and add it to our collection.

DbConnectionOptions connectionOptions = CreateConnectionOptions(key.ConnectionString, userConnectionOptions);
if (null == connectionOptions)
if (connectionOptions == null)
{
throw ADP.InternalConnectionError(ADP.ConnectionError.ConnectionOptionsMissing);
}

if (null == userConnectionOptions)
if (userConnectionOptions == null)
{ // we only allow one expansion on the connection string

userConnectionOptions = connectionOptions;
Expand All @@ -236,7 +236,7 @@ internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnectionPoolKey key, D
}

// We don't support connection pooling on Win9x
if (null == poolOptions)
if (poolOptions == null)
{
if (null != connectionPoolGroup)
{
Expand Down Expand Up @@ -279,7 +279,7 @@ internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnectionPoolKey key, D
Debug.Assert(null != connectionPoolGroup, "how did we not create a pool entry?");
Debug.Assert(null != userConnectionOptions, "how did we not have user connection options?");
}
else if (null == userConnectionOptions)
else if (userConnectionOptions == null)
{
userConnectionOptions = connectionPoolGroup.ConnectionOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ public ConnectionState State

internal void AddWeakReference(object value, int tag)
{
if (null == _referenceCollection)
if (_referenceCollection == null)
{
_referenceCollection = CreateReferenceCollection();
if (null == _referenceCollection)
if (_referenceCollection == null)
{
throw ADP.InternalError(ADP.InternalErrorCode.CreateReferenceCollectionReturnedNull);
}
Expand Down Expand Up @@ -349,7 +349,7 @@ protected bool TryOpenConnectionInternal(DbConnection outerConnection, DbConnect
connectionFactory.SetInnerConnectionTo(outerConnection, this);
throw;
}
if (null == openConnection)
if (openConnection == null)
{
connectionFactory.SetInnerConnectionTo(outerConnection, this);
throw ADP.InternalConnectionError(ADP.ConnectionError.GetConnectionReturnsNull);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal static string ExpandDataDirectory(string keyword, string value)
// find the replacement path
object rootFolderObject = AppDomain.CurrentDomain.GetData("DataDirectory");
var rootFolderPath = (rootFolderObject as string);
if ((null != rootFolderObject) && (null == rootFolderPath))
if ((null != rootFolderObject) && rootFolderPath == null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 @@ -43,7 +43,7 @@ internal bool TryGetConnection(DbConnection owningConnection, TaskCompletionSour
poolGroup = GetConnectionPoolGroup(owningConnection);
// Doing this on the callers thread is important because it looks up the WindowsIdentity from the thread.
connectionPool = GetConnectionPool(owningConnection, poolGroup);
if (null == connectionPool)
if (connectionPool == null)
{
// If GetConnectionPool returns null, we can be certain that
// this connection should not be pooled via DbConnectionPool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected internal Transaction EnlistedTransaction
set
{
Transaction currentEnlistedTransaction = _enlistedTransaction;
if (((null == currentEnlistedTransaction) && (null != value))
if ((currentEnlistedTransaction == null && (null != value))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ((currentEnlistedTransaction == null && (null != value))
if ((currentEnlistedTransaction == null && (value != null))

|| ((null != currentEnlistedTransaction) && !currentEnlistedTransaction.Equals(value)))
{ // WebData 20000024

Expand Down Expand Up @@ -354,7 +354,7 @@ virtual internal void DelegatedTransactionEnded()

DbConnectionPool pool = Pool;

if (null == pool)
if (pool == null)
{
throw ADP.InternalError(ADP.InternalErrorCode.PooledObjectWithoutPool); // pooled connection does not have a pool
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ private DbConnectionInternal CreateObject(DbConnection owningObject, DbConnectio
try
{
newObj = _connectionFactory.CreatePooledConnection(this, owningObject, _connectionPoolGroup.ConnectionOptions, _connectionPoolGroup.PoolKey, userOptions);
if (null == newObj)
if (newObj == null)
{
throw ADP.InternalError(ADP.InternalErrorCode.CreateObjectReturnedNull); // CreateObject succeeded, but null object
}
Expand Down Expand Up @@ -1172,7 +1172,7 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj
obj = GetFromTransactedPool(out transaction);
}

if (null == obj)
if (obj == null)
{
Interlocked.Increment(ref _waitCount);

Expand Down Expand Up @@ -1217,7 +1217,7 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj
}
catch
{
if (null == obj)
if (obj == null)
{
Interlocked.Decrement(ref _waitCount);
}
Expand All @@ -1233,7 +1233,7 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj
}
}

if (null == obj)
if (obj == null)
{
// If we were not able to create an object, check to see if
// we reached MaxPoolSize. If so, we will no longer wait on
Expand Down Expand Up @@ -1309,7 +1309,7 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj
DestroyObject(obj);
obj = null;
}
} while (null == obj);
} while (obj == null);
}

if (null != obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static SqlAuthenticationProviderManager()
{
// New configuration section "SqlClientAuthenticationProviders" for Microsoft.Data.SqlClient accepted to avoid conflicts with older one.
configurationSection = FetchConfigurationSection<SqlClientAuthenticationProviderConfigurationSection>(SqlClientAuthenticationProviderConfigurationSection.Name);
if (null == configurationSection)
if (configurationSection == null)
{
// If configuration section is not yet found, try with old Configuration Section name for backwards compatibility
configurationSection = FetchConfigurationSection<SqlAuthenticationProviderConfigurationSection>(SqlAuthenticationProviderConfigurationSection.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i

isInTransaction = _connection.HasLocalTransaction;
// Throw if there is a transaction but no flag is set
if (isInTransaction && null == _externalTransaction && null == _internalTransaction && (_connection.Parser != null && _connection.Parser.CurrentTransaction != null && _connection.Parser.CurrentTransaction.IsLocal))
if (isInTransaction && _externalTransaction == null && _internalTransaction == null && (_connection.Parser != null && _connection.Parser.CurrentTransaction != null && _connection.Parser.CurrentTransaction.IsLocal))
{
throw SQL.BulkLoadExistingTransaction();
}
Expand Down Expand Up @@ -1281,7 +1281,7 @@ private SourceColumnMetadata GetColumnMetadata(int ordinal)

private void CreateOrValidateConnection(string method)
{
if (null == _connection)
if (_connection == null)
{
throw ADP.ConnectionRequired(method);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string e
// Validate the input parameters
ValidateNonEmptyKeyPath(masterKeyPath, isSystemOp: true);

if (null == encryptedColumnEncryptionKey)
if (encryptedColumnEncryptionKey == null)
{
throw SQL.NullEncryptedColumnEncryptionKey();
}
Expand Down Expand Up @@ -126,7 +126,7 @@ public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string e
// Validate the input parameters
ValidateNonEmptyKeyPath(masterKeyPath, isSystemOp: false);

if (null == columnEncryptionKey)
if (columnEncryptionKey == null)
{
throw SQL.NullColumnEncryptionKey();
}
Expand Down Expand Up @@ -231,7 +231,7 @@ public override bool VerifyColumnMasterKeyMetadata(string masterKeyPath, bool al
private void ValidateEncryptionAlgorithm(string encryptionAlgorithm, bool isSystemOp)
{
// This validates that the encryption algorithm is RSA_OAEP
if (null == encryptionAlgorithm)
if (encryptionAlgorithm == null)
{
throw SQL.NullKeyEncryptionAlgorithm(isSystemOp);
}
Expand All @@ -251,7 +251,7 @@ private void ValidateNonEmptyKeyPath(string masterKeyPath, bool isSystemOp)
{
if (string.IsNullOrWhiteSpace(masterKeyPath))
{
if (null == masterKeyPath)
if (masterKeyPath == null)
{
throw SQL.NullCngKeyPath(isSystemOp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string e
// Validate the input parameters
ValidateNonEmptyCSPKeyPath(masterKeyPath, isSystemOp: true);

if (null == encryptedColumnEncryptionKey)
if (encryptedColumnEncryptionKey == null)
{
throw SQL.NullEncryptedColumnEncryptionKey();
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string e
// Validate the input parameters
ValidateNonEmptyCSPKeyPath(masterKeyPath, isSystemOp: false);

if (null == columnEncryptionKey)
if (columnEncryptionKey == null)
{
throw SQL.NullColumnEncryptionKey();
}
Expand Down Expand Up @@ -239,7 +239,7 @@ public override bool VerifyColumnMasterKeyMetadata(string masterKeyPath, bool al
private void ValidateEncryptionAlgorithm(string encryptionAlgorithm, bool isSystemOp)
{
// This validates that the encryption algorithm is RSA_OAEP
if (null == encryptionAlgorithm)
if (encryptionAlgorithm == null)
{
throw SQL.NullKeyEncryptionAlgorithm(isSystemOp);
}
Expand All @@ -260,7 +260,7 @@ private void ValidateNonEmptyCSPKeyPath(string masterKeyPath, bool isSystemOp)
{
if (string.IsNullOrWhiteSpace(masterKeyPath))
{
if (null == masterKeyPath)
if (masterKeyPath == null)
{
throw SQL.NullCspKeyPath(isSystemOp);
}
Expand Down
Loading
Loading