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

More fixes for SonarQube warnings and coding standards #1969

Merged
merged 13 commits into from
Nov 22, 2022
Merged
133 changes: 48 additions & 85 deletions src/main/java/com/microsoft/sqlserver/jdbc/DDC.java

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/main/java/com/microsoft/sqlserver/jdbc/DLLException.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ int getErrCode() {
return this.errCode;
}

String GetParam1() {
String getParam1() {
return this.param1;
}

String GetParam2() {
String getParam2() {
return this.param2;
}

String GetParam3() {
String getParam3() {
return this.param3;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/DataTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ enum TDSType {

private static final int MAXELEMENTS = 256;
private static final TDSType[] VALUES = values();
private static final TDSType valuesTypes[] = new TDSType[MAXELEMENTS];
private static final TDSType[] valuesTypes = new TDSType[MAXELEMENTS];

byte byteValue() {
return (byte) intValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ boolean getUseFailoverPartner() {
return useFailoverPartner;
}

FailoverInfo(String failover, SQLServerConnection con, boolean actualFailoverPartner) {
FailoverInfo(String failover, boolean actualFailoverPartner) {
failoverPartner = failover;
useFailoverPartner = actualFailoverPartner;
portNumber = -1; // init to -1 to make sure that the user of this class calls the failover check before getting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ static FailoverInfo getFailoverInfo(SQLServerConnection connection, String prima
// failover server name provided
// by the server. The map is only populated if the server sends failover info.
static void putFailoverInfo(SQLServerConnection connection, String primaryServer, String instance, String database,
FailoverInfo actualFailoverInfo, boolean actualuseFailover,
String failoverPartner) throws SQLServerException {
FailoverInfo actualFailoverInfo, boolean actualuseFailover, String failoverPartner) {
FailoverInfo fo;

LOCK.lock();
Expand Down
249 changes: 117 additions & 132 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @deprecated as of 8.1.0, because the interface contains methods which are not called as part of actual bulk copy
* process. Use {@link ISQLServerBulkData}} instead.
*/
@Deprecated
@Deprecated(since = "8.1.0")
public interface ISQLServerBulkRecord extends ISQLServerBulkData {
/**
* Returns whether the column represents an identity column.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement,
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
* when an error occurs
*
* @deprecated
*/
@Deprecated
@Deprecated(since = "6.5.4", forRemoval = true)
BigDecimal getBigDecimal(String parameterName, int scale) throws SQLServerException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,21 +409,22 @@ CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold,
String getIPAddressPreference();

/**
* Deprecated. Time-to-live is no longer supported for the cached Managed Identity tokens.
* This method will always return 0 and is for backwards compatibility only.
*
* @return Method will always return 0.
* @deprecated Time-to-live is no longer supported for the cached Managed Identity tokens.
*/
@Deprecated
@Deprecated(since = "12.1.0", forRemoval = true)
int getMsiTokenCacheTtl();

/**
* Deprecated. Time-to-live is no longer supported for the cached Managed Identity tokens.
* This method is a no-op for backwards compatibility only.
* @deprecated Time-to-live is no longer supported for the cached Managed Identity tokens.
* This method is a no-op for backwards compatibility only.
*
* @param timeToLive
* Time-to-live is no longer supported.
* @deprecated Time-to-live is no longer supported for the cached Managed Identity tokens.
*/
@Deprecated
@Deprecated(since = "12.1.0", forRemoval = true)
void setMsiTokenCacheTtl(int timeToLive);
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
/**
* Sets the option whether TLS encryption is used.
*
* @deprecated Use {@link ISQLServerDataSource#setEncrypt(String encryptOption)} instead
* @param encryptOption
* TLS encrypt option. Default is true
* @deprecated Use {@link ISQLServerDataSource#setEncrypt(String encryptOption)} instead
*/
@Deprecated
@Deprecated(since = "10.1.0", forRemoval = true)
void setEncrypt(boolean encryptOption);

/**
Expand Down Expand Up @@ -788,22 +788,23 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Sets the login configuration file for Kerberos authentication. This overrides the default configuration <i>
* SQLJDBCDriver </i>
*
* @deprecated Use {@link ISQLServerDataSource#setJAASConfigurationName(String configurationName)} instead
*
* @param configurationName
* the configuration name
* @deprecated Use {@link ISQLServerDataSource#setJAASConfigurationName(String configurationName)} instead
*
*/
@Deprecated
@Deprecated(since = "9.3.0", forRemoval = true)
void setJASSConfigurationName(String configurationName);

/**
* Returns the login configuration file for Kerberos authentication.
* *
lilgreenbird marked this conversation as resolved.
Show resolved Hide resolved
*
* @return login configuration file name
* @deprecated Use {@link ISQLServerDataSource#getJAASConfigurationName()} instead
*
* @return login configuration file name
*/
@Deprecated
@Deprecated(since = "9.3.0", forRemoval = true)
String getJASSConfigurationName();

/**
Expand Down Expand Up @@ -932,24 +933,23 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
void setUseBulkCopyForBatchInsert(boolean useBulkCopyForBatchInsert);

/**
* This method is deprecated. Use {@link ISQLServerDataSource#setUser(String user)} instead.
*
* Sets the client id to be used to retrieve the access token for a user-assigned Managed Identity.
*
* @param managedIdentityClientId
* Client ID of the user-assigned Managed Identity.
* @deprecated Use {@link ISQLServerDataSource#setUser(String user)} instead.
*/
@Deprecated
@Deprecated(since = "12.1.0", forRemoval = true)
void setMSIClientId(String managedIdentityClientId);

/**
* This method is deprecated. Use {@link ISQLServerDataSource#getUser()} instead.
*
* Returns the value for the connection property 'msiClientId'.
*
* @return msiClientId property value
*
* @deprecated Use {@link ISQLServerDataSource#getUser()} instead.
*/
@Deprecated
@Deprecated(since = "12.1.0", forRemoval = true)
String getMSIClientId();

/**
Expand Down Expand Up @@ -1123,34 +1123,35 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
void setSendTemporalDataTypesAsStringForBulkCopy(boolean sendTemporalDataTypesAsStringForBulkCopy);

/**
*
* Returns the value for the connection property 'AADSecurePrincipalId'.
*
* @deprecated Use {@link ISQLServerDataSource#getUser()} instead
*
* @return 'AADSecurePrincipalId' property value.
* @deprecated Use {@link ISQLServerDataSource#getUser()} instead
*/
@Deprecated
@Deprecated(since = "9.4.1", forRemoval = true)
String getAADSecurePrincipalId();

/**
*
* Sets the 'AADSecurePrincipalId' connection property used for Active Directory Service Principal authentication.
*
* @deprecated Use {@link ISQLServerDataSource#setUser(String user)} instead
* @param AADSecurePrincipalId
* Active Directory Service Principal Id.
* @deprecated Use {@link ISQLServerDataSource#setUser(String user)} instead
*/
@Deprecated
@Deprecated(since = "9.4.1", forRemoval = true)
void setAADSecurePrincipalId(String AADSecurePrincipalId);

/**
* Sets the 'AADSecurePrincipalSecret' connection property used for Active Directory Service Principal
* authentication.
*
* @deprecated Use {@link ISQLServerDataSource#setPassword(String password)} instead
* @param AADSecurePrincipalSecret
* Active Directory Service Principal secret.
* @deprecated Use {@link ISQLServerDataSource#setPassword(String password)} instead
*/
@Deprecated
@Deprecated(since = "9.4.1", forRemoval = true)
void setAADSecurePrincipalSecret(String AADSecurePrincipalSecret);

/**
Expand Down Expand Up @@ -1214,22 +1215,26 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
String getPrepareMethod();

/**
* Deprecated. Time-to-live is no longer supported for the cached Managed Identity tokens.
* Time-to-live is no longer supported for the cached Managed Identity tokens.
* This method is a no-op for backwards compatibility only.
*
* @param timeToLive
* Time-to-live is no longer supported.
*
* @deprecated
*/
@Deprecated
@Deprecated(since = "12.1.0", forRemoval = true)
void setMsiTokenCacheTtl(int timeToLive);

/**
* Deprecated. Time-to-live is no longer supported for the cached Managed Identity tokens.
* Time-to-live is no longer supported for the cached Managed Identity tokens.
* This method will always return 0 and is for backwards compatibility only.
*
* @return Method will always return 0.
*
* @deprecated
*/
@Deprecated
@Deprecated(since = "12.1.0", forRemoval = true)
int getMsiTokenCacheTtl();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,11 @@ void validateDHPublicKey() throws SQLServerException, GeneralSecurityException {
ByteBuffer enclavePKBuffer = ByteBuffer.wrap(enclavePK).order(ByteOrder.LITTLE_ENDIAN);
byte[] rsa1 = new byte[4];
enclavePKBuffer.get(rsa1);
int bitCount = enclavePKBuffer.getInt();
// bit count unused
int publicExponentLength = enclavePKBuffer.getInt();
int publicModulusLength = enclavePKBuffer.getInt();
int prime1 = enclavePKBuffer.getInt();
int prime2 = enclavePKBuffer.getInt();
// prime 1 unused
// prime 2 unused
byte[] exponent = new byte[publicExponentLength];
enclavePKBuffer.get(exponent);
byte[] modulus = new byte[publicModulusLength];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,34 +110,32 @@ void parseInitialSessionStateData(byte[] data, byte[][] sessionStateInitial) thr
}

void incrementUnprocessedResponseCount() {
if (connection.getRetryCount() > 0 && !isReconnectRunning()) {
if (unprocessedResponseCount.incrementAndGet() < 0) {
/*
* When this number rolls over, connection recovery is disabled for the rest of the life of the
* connection.
*/
if (loggerExternal.isLoggable(Level.FINER)) {
loggerExternal.finer("unprocessedResponseCount < 0 on increment. Disabling connection resiliency.");
}

setConnectionRecoveryPossible(false);
if ((connection.getRetryCount() > 0 && !isReconnectRunning())
&& (unprocessedResponseCount.incrementAndGet() < 0)) {
/*
* When this number rolls over, connection recovery is disabled for the rest of the life of the
* connection.
*/
if (loggerExternal.isLoggable(Level.FINER)) {
loggerExternal.finer("unprocessedResponseCount < 0 on increment. Disabling connection resiliency.");
}

setConnectionRecoveryPossible(false);
}
}

void decrementUnprocessedResponseCount() {
if (connection.getRetryCount() > 0 && !isReconnectRunning()) {
if (unprocessedResponseCount.decrementAndGet() < 0) {
/*
* When this number rolls over, connection recovery is disabled for the rest of the life of the
* connection.
*/
if (loggerExternal.isLoggable(Level.FINER)) {
loggerExternal.finer("unprocessedResponseCount < 0 on decrement. Disabling connection resiliency.");
}

setConnectionRecoveryPossible(false);
if ((connection.getRetryCount() > 0 && !isReconnectRunning())
&& (unprocessedResponseCount.decrementAndGet() < 0)) {
/*
* When this number rolls over, connection recovery is disabled for the rest of the life of the
* connection.
*/
if (loggerExternal.isLoggable(Level.FINER)) {
loggerExternal.finer("unprocessedResponseCount < 0 on decrement. Disabling connection resiliency.");
}

setConnectionRecoveryPossible(false);
}
}

Expand Down Expand Up @@ -428,6 +426,7 @@ private ReconnectThread() {}

}

@Override
public void run() {
if (loggerExternal.isLoggable(Level.FINER)) {
loggerExternal.finer("Starting ReconnectThread for command: " + command.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.ArrayList;
import java.util.List;


/**
* The HTTP pipeline builder which includes all the necessary HTTP pipeline policies that will be applied for
* sending and receiving HTTP requests to the Key Vault service.
Expand All @@ -41,20 +42,21 @@ final class KeyVaultHttpPipelineBuilder {
* Builds the HTTP pipeline with all the necessary HTTP policies included in the pipeline.
*
* @return A fully built HTTP pipeline including the default HTTP client.
* @throws SQLServerException If the {@link KeyVaultCustomCredentialPolicy} policy cannot be added to the pipeline.
* @throws SQLServerException
* If the {@link KeyVaultCustomCredentialPolicy} policy cannot be added to the pipeline.
*/
HttpPipeline buildPipeline() throws SQLServerException {
// Closest to API goes first, closest to wire goes last.
final List<HttpPipelinePolicy> policies = new ArrayList<>();
final List<HttpPipelinePolicy> pol = new ArrayList<>();

HttpPolicyProviders.addBeforeRetryPolicies(policies);
policies.add(retryPolicy);
policies.add(new KeyVaultCustomCredentialPolicy(credential));
policies.addAll(this.policies);
HttpPolicyProviders.addAfterRetryPolicies(policies);
policies.add(new HttpLoggingPolicy(httpLogOptions));
HttpPolicyProviders.addBeforeRetryPolicies(pol);
pol.add(retryPolicy);
pol.add(new KeyVaultCustomCredentialPolicy(credential));
pol.addAll(this.policies);
HttpPolicyProviders.addAfterRetryPolicies(pol);
pol.add(new HttpLoggingPolicy(httpLogOptions));

return new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])).build();
return new HttpPipelineBuilder().policies(pol.toArray(new HttpPipelinePolicy[0])).build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public int read(byte[] b) throws IOException {
* @exception IOException
* if an I/O error occurs.
*/
@Override
public int read(byte[] b, int offset, int maxBytes) throws IOException {
// If b is null, a NullPointerException is thrown.
if (null == b)
Expand Down
Loading