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

SonarQube Fixes to abide rules + Warnings fixed #933

Merged
merged 5 commits into from
Jan 14, 2019
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
8 changes: 7 additions & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/AE.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package com.microsoft.sqlserver.jdbc;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -121,7 +122,12 @@ void add(byte[] encryptedKey, int dbId, int keyId, int keyVersion, byte[] mdVers
/**
* Contains all CEKs, each row represents one unique CEK (represented by CekTableEntry).
*/
class CekTable {
class CekTable implements Serializable {
/**
* Always update serialVersionUID when prompted.
*/
private static final long serialVersionUID = -4568542970907052239L;

CekTableEntry[] keyList;

CekTable(int tableSize) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ void sendByRPC(TDSWriter tdsWriter, SQLServerConnection conn) throws SQLServerEx
try {
// this is for updateRow() stuff
updaterDTV.sendCryptoMetaData(cryptoMetadata, tdsWriter);
updaterDTV.jdbcTypeSetByUser(getJdbcTypeSetByUser(), getValueLength());
updaterDTV.setJdbcTypeSetByUser(getJdbcTypeSetByUser(), getValueLength());

// Otherwise, send the updated value via RPC
updaterDTV.sendByRPC(baseColumnName, typeInfo,
Expand Down
45 changes: 20 additions & 25 deletions src/main/java/com/microsoft/sqlserver/jdbc/DDC.java
Original file line number Diff line number Diff line change
Expand Up @@ -573,14 +573,29 @@ static final Object convertStreamToObject(BaseInputStream stream, TypeInfo typeI

try {
switch (jdbcType) {
case CLOB:
return new SQLServerClob(stream, typeInfo);
case NCLOB:
return new SQLServerNClob(stream, typeInfo);
case SQLXML:
return new SQLServerSQLXML(stream, getterArgs, typeInfo);
case BINARY:
case VARBINARY:
case LONGVARBINARY:
case BLOB:
// Where allowed, streams convert directly to binary representation
if (StreamType.BINARY == getterArgs.streamType)
return stream;
if (JDBCType.BLOB == jdbcType)
return new SQLServerBlob(stream);
return stream.getBytes();
case CHAR:
case VARCHAR:
case LONGVARCHAR:
case NCHAR:
case NVARCHAR:
case LONGNVARCHAR:
default:

// Binary streams to character types:
// - Direct conversion to ASCII stream
// - Convert as hexized value to other character types
Expand All @@ -597,12 +612,14 @@ static final Object convertStreamToObject(BaseInputStream stream, TypeInfo typeI
return Util.readGUID(byteValue);
} else if (JDBCType.GEOMETRY == jdbcType) {
if (!typeInfo.getSSTypeName().equalsIgnoreCase(jdbcType.toString())) {
DataTypes.throwConversionError(typeInfo.getSSTypeName().toUpperCase(), jdbcType.toString());
DataTypes.throwConversionError(typeInfo.getSSTypeName().toUpperCase(),
jdbcType.toString());
}
return Geometry.STGeomFromWKB(byteValue);
} else if (JDBCType.GEOGRAPHY == jdbcType) {
if (!typeInfo.getSSTypeName().equalsIgnoreCase(jdbcType.toString())) {
DataTypes.throwConversionError(typeInfo.getSSTypeName().toUpperCase(), jdbcType.toString());
DataTypes.throwConversionError(typeInfo.getSSTypeName().toUpperCase(),
jdbcType.toString());
}
return Geography.STGeomFromWKB(byteValue);
} else {
Expand Down Expand Up @@ -643,28 +660,6 @@ static final Object convertStreamToObject(BaseInputStream stream, TypeInfo typeI
return convertStringToObject(new String(stream.getBytes(), typeInfo.getCharset()),
typeInfo.getCharset(), jdbcType, getterArgs.streamType);

case CLOB:
return new SQLServerClob(stream, typeInfo);

case NCLOB:
return new SQLServerNClob(stream, typeInfo);
case SQLXML:
return new SQLServerSQLXML(stream, getterArgs, typeInfo);

case BINARY:
case VARBINARY:
case LONGVARBINARY:
case BLOB:

// Where allowed, streams convert directly to binary representation

if (StreamType.BINARY == getterArgs.streamType)
return stream;

if (JDBCType.BLOB == jdbcType)
return new SQLServerBlob(stream);

return stream.getBytes();
}
}

Expand Down
99 changes: 49 additions & 50 deletions src/main/java/com/microsoft/sqlserver/jdbc/DataTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -612,55 +612,56 @@ else if (!sendStringParametersAsUnicode && fromJavaType == JavaType.BYTEARRAY


enum JDBCType {
UNKNOWN(Category.UNKNOWN, 999, "java.lang.Object"),
ARRAY(Category.UNKNOWN, java.sql.Types.ARRAY, "java.lang.Object"),
BIGINT(Category.NUMERIC, java.sql.Types.BIGINT, "java.lang.Long"),
UNKNOWN(Category.UNKNOWN, 999, Object.class.getName()),
ARRAY(Category.UNKNOWN, java.sql.Types.ARRAY, Object.class.getName()),
BIGINT(Category.NUMERIC, java.sql.Types.BIGINT, Long.class.getName()),
BINARY(Category.BINARY, java.sql.Types.BINARY, "[B"),
BIT(Category.NUMERIC, java.sql.Types.BIT, "java.lang.Boolean"),
BLOB(Category.BLOB, java.sql.Types.BLOB, "java.sql.Blob"),
BOOLEAN(Category.NUMERIC, java.sql.Types.BOOLEAN, "java.lang.Boolean"),
CHAR(Category.CHARACTER, java.sql.Types.CHAR, "java.lang.String"),
CLOB(Category.CLOB, java.sql.Types.CLOB, "java.sql.Clob"),
DATALINK(Category.UNKNOWN, java.sql.Types.DATALINK, "java.lang.Object"),
DATE(Category.DATE, java.sql.Types.DATE, "java.sql.Date"),
DATETIMEOFFSET(Category.DATETIMEOFFSET, microsoft.sql.Types.DATETIMEOFFSET, "microsoft.sql.DateTimeOffset"),
DECIMAL(Category.NUMERIC, java.sql.Types.DECIMAL, "java.math.BigDecimal"),
DISTINCT(Category.UNKNOWN, java.sql.Types.DISTINCT, "java.lang.Object"),
DOUBLE(Category.NUMERIC, java.sql.Types.DOUBLE, "java.lang.Double"),
FLOAT(Category.NUMERIC, java.sql.Types.FLOAT, "java.lang.Double"),
INTEGER(Category.NUMERIC, java.sql.Types.INTEGER, "java.lang.Integer"),
JAVA_OBJECT(Category.UNKNOWN, java.sql.Types.JAVA_OBJECT, "java.lang.Object"),
LONGNVARCHAR(Category.LONG_NCHARACTER, -16, "java.lang.String"),
BIT(Category.NUMERIC, java.sql.Types.BIT, Boolean.class.getName()),
BLOB(Category.BLOB, java.sql.Types.BLOB, java.sql.Blob.class.getName()),
BOOLEAN(Category.NUMERIC, java.sql.Types.BOOLEAN, Boolean.class.getName()),
CHAR(Category.CHARACTER, java.sql.Types.CHAR, String.class.getName()),
CLOB(Category.CLOB, java.sql.Types.CLOB, java.sql.Clob.class.getName()),
DATALINK(Category.UNKNOWN, java.sql.Types.DATALINK, Object.class.getName()),
DATE(Category.DATE, java.sql.Types.DATE, java.sql.Date.class.getName()),
DATETIMEOFFSET(Category.DATETIMEOFFSET, microsoft.sql.Types.DATETIMEOFFSET, microsoft.sql.DateTimeOffset.class
.getName()),
DECIMAL(Category.NUMERIC, java.sql.Types.DECIMAL, BigDecimal.class.getName()),
DISTINCT(Category.UNKNOWN, java.sql.Types.DISTINCT, Object.class.getName()),
DOUBLE(Category.NUMERIC, java.sql.Types.DOUBLE, Double.class.getName()),
FLOAT(Category.NUMERIC, java.sql.Types.FLOAT, Double.class.getName()),
INTEGER(Category.NUMERIC, java.sql.Types.INTEGER, Integer.class.getName()),
JAVA_OBJECT(Category.UNKNOWN, java.sql.Types.JAVA_OBJECT, Object.class.getName()),
LONGNVARCHAR(Category.LONG_NCHARACTER, -16, String.class.getName()),
LONGVARBINARY(Category.LONG_BINARY, java.sql.Types.LONGVARBINARY, "[B"),
LONGVARCHAR(Category.LONG_CHARACTER, java.sql.Types.LONGVARCHAR, "java.lang.String"),
NCHAR(Category.NCHARACTER, -15, "java.lang.String"),
NCLOB(Category.NCLOB, 2011, "java.sql.NClob"),
NULL(Category.UNKNOWN, java.sql.Types.NULL, "java.lang.Object"),
NUMERIC(Category.NUMERIC, java.sql.Types.NUMERIC, "java.math.BigDecimal"),
NVARCHAR(Category.NCHARACTER, -9, "java.lang.String"),
OTHER(Category.UNKNOWN, java.sql.Types.OTHER, "java.lang.Object"),
REAL(Category.NUMERIC, java.sql.Types.REAL, "java.lang.Float"),
REF(Category.UNKNOWN, java.sql.Types.REF, "java.lang.Object"),
ROWID(Category.UNKNOWN, -8, "java.lang.Object"),
SMALLINT(Category.NUMERIC, java.sql.Types.SMALLINT, "java.lang.Short"),
SQLXML(Category.SQLXML, 2009, "java.lang.Object"),
STRUCT(Category.UNKNOWN, java.sql.Types.STRUCT, "java.lang.Object"),
TIME(Category.TIME, java.sql.Types.TIME, "java.sql.Time"),
TIME_WITH_TIMEZONE(Category.TIME_WITH_TIMEZONE, 2013, "java.time.OffsetTime"),
TIMESTAMP(Category.TIMESTAMP, java.sql.Types.TIMESTAMP, "java.sql.Timestamp"),
TIMESTAMP_WITH_TIMEZONE(Category.TIMESTAMP_WITH_TIMEZONE, 2014, "java.time.OffsetDateTime"),
TINYINT(Category.NUMERIC, java.sql.Types.TINYINT, "java.lang.Short"),
LONGVARCHAR(Category.LONG_CHARACTER, java.sql.Types.LONGVARCHAR, String.class.getName()),
NCHAR(Category.NCHARACTER, -15, String.class.getName()),
NCLOB(Category.NCLOB, 2011, java.sql.NClob.class.getName()),
NULL(Category.UNKNOWN, java.sql.Types.NULL, Object.class.getName()),
NUMERIC(Category.NUMERIC, java.sql.Types.NUMERIC, BigDecimal.class.getName()),
NVARCHAR(Category.NCHARACTER, -9, String.class.getName()),
OTHER(Category.UNKNOWN, java.sql.Types.OTHER, Object.class.getName()),
REAL(Category.NUMERIC, java.sql.Types.REAL, Float.class.getName()),
REF(Category.UNKNOWN, java.sql.Types.REF, Object.class.getName()),
ROWID(Category.UNKNOWN, -8, Object.class.getName()),
SMALLINT(Category.NUMERIC, java.sql.Types.SMALLINT, Short.class.getName()),
SQLXML(Category.SQLXML, 2009, Object.class.getName()),
STRUCT(Category.UNKNOWN, java.sql.Types.STRUCT, Object.class.getName()),
TIME(Category.TIME, java.sql.Types.TIME, java.sql.Time.class.getName()),
TIME_WITH_TIMEZONE(Category.TIME_WITH_TIMEZONE, 2013, java.time.OffsetTime.class.getName()),
TIMESTAMP(Category.TIMESTAMP, java.sql.Types.TIMESTAMP, java.sql.Timestamp.class.getName()),
TIMESTAMP_WITH_TIMEZONE(Category.TIMESTAMP_WITH_TIMEZONE, 2014, java.time.OffsetDateTime.class.getName()),
TINYINT(Category.NUMERIC, java.sql.Types.TINYINT, Short.class.getName()),
VARBINARY(Category.BINARY, java.sql.Types.VARBINARY, "[B"),
VARCHAR(Category.CHARACTER, java.sql.Types.VARCHAR, "java.lang.String"),
MONEY(Category.NUMERIC, microsoft.sql.Types.MONEY, "java.math.BigDecimal"),
SMALLMONEY(Category.NUMERIC, microsoft.sql.Types.SMALLMONEY, "java.math.BigDecimal"),
TVP(Category.TVP, microsoft.sql.Types.STRUCTURED, "java.lang.Object"),
DATETIME(Category.TIMESTAMP, microsoft.sql.Types.DATETIME, "java.sql.Timestamp"),
SMALLDATETIME(Category.TIMESTAMP, microsoft.sql.Types.SMALLDATETIME, "java.sql.Timestamp"),
GUID(Category.CHARACTER, microsoft.sql.Types.GUID, "java.lang.String"),
SQL_VARIANT(Category.SQL_VARIANT, microsoft.sql.Types.SQL_VARIANT, "java.lang.Object"),
GEOMETRY(Category.GEOMETRY, microsoft.sql.Types.GEOMETRY, "java.lang.Object"),
GEOGRAPHY(Category.GEOGRAPHY, microsoft.sql.Types.GEOGRAPHY, "java.lang.Object");
VARCHAR(Category.CHARACTER, java.sql.Types.VARCHAR, String.class.getName()),
MONEY(Category.NUMERIC, microsoft.sql.Types.MONEY, BigDecimal.class.getName()),
SMALLMONEY(Category.NUMERIC, microsoft.sql.Types.SMALLMONEY, BigDecimal.class.getName()),
TVP(Category.TVP, microsoft.sql.Types.STRUCTURED, Object.class.getName()),
DATETIME(Category.TIMESTAMP, microsoft.sql.Types.DATETIME, java.sql.Timestamp.class.getName()),
SMALLDATETIME(Category.TIMESTAMP, microsoft.sql.Types.SMALLDATETIME, java.sql.Timestamp.class.getName()),
GUID(Category.CHARACTER, microsoft.sql.Types.GUID, String.class.getName()),
SQL_VARIANT(Category.SQL_VARIANT, microsoft.sql.Types.SQL_VARIANT, Object.class.getName()),
GEOMETRY(Category.GEOMETRY, microsoft.sql.Types.GEOMETRY, Object.class.getName()),
GEOGRAPHY(Category.GEOGRAPHY, microsoft.sql.Types.GEOGRAPHY, Object.class.getName());

final Category category;
private final int intValue;
Expand Down Expand Up @@ -1143,8 +1144,6 @@ static final void throwConversionError(String fromType, String toType) throws SQ
final static int MAX_VARTYPE_MAX_CHARS = 0x3FFFFFFF;
final static int MAX_VARTYPE_MAX_BYTES = 0x7FFFFFFF;

static private java.util.logging.Logger stmtDT;

// Special length indicator for varchar(max), nvarchar(max) and varbinary(max).
static final int MAXTYPE_LENGTH = 0xFFFF;

Expand All @@ -1160,12 +1159,12 @@ static final long getCheckedLength(SQLServerConnection con, JDBCType jdbcType, l
case NVARCHAR:
case LONGNVARCHAR:
case NCLOB:
assert MAX_VARTYPE_MAX_CHARS == NTEXT_MAX_CHARS;
// assert MAX_VARTYPE_MAX_CHARS == NTEXT_MAX_CHARS;
maxLength = DataTypes.MAX_VARTYPE_MAX_CHARS;
break;

default:
assert MAX_VARTYPE_MAX_BYTES == IMAGE_TEXT_MAX_BYTES;
// assert MAX_VARTYPE_MAX_BYTES == IMAGE_TEXT_MAX_BYTES;
maxLength = DataTypes.MAX_VARTYPE_MAX_BYTES;
break;
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/FailOverInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package com.microsoft.sqlserver.jdbc;

import java.io.Serializable;
import java.text.MessageFormat;
import java.util.logging.Level;

Expand Down Expand Up @@ -113,7 +114,12 @@ synchronized void failoverAdd(SQLServerConnection connection, boolean actualUseF
// We need this class so during a connection open we can keep a copy of the current failover info stable
// This is also used to keep the standalone primary server connection information.
//
final class ServerPortPlaceHolder {
final class ServerPortPlaceHolder implements Serializable {
/**
* Always update serialVersionUID when prompted.
*/
private static final long serialVersionUID = 7393779415545731523L;

private final String serverName;
private final int port;
private final String instanceName;
Expand Down
38 changes: 31 additions & 7 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
Expand Down Expand Up @@ -543,7 +544,12 @@ private UTC() {}
}


final class TDSChannel {
final class TDSChannel implements Serializable {
/**
* Always update serialVersionUID when prompted.
*/
private static final long serialVersionUID = -866497813437384090L;

private static final Logger logger = Logger.getLogger("com.microsoft.sqlserver.jdbc.internals.TDS.Channel");

final Logger getLogger() {
Expand Down Expand Up @@ -578,6 +584,7 @@ final TDSReader getReader(TDSCommand command) {
* Socket providing the communications interface to the driver. For SSL-encrypted connections, this is the SSLSocket
* wrapped around the TCP socket. For unencrypted connections, it is just the TCP socket itself.
*/
@SuppressWarnings("unused")
private Socket channelSocket;

/*
Expand Down Expand Up @@ -2586,6 +2593,7 @@ private void findSocketUsingJavaNIO(InetAddress[] inetAddrs, int portNumber,
sChannel.configureBlocking(false);

// register the channel for connect event
@SuppressWarnings("unused")
int ops = SelectionKey.OP_CONNECT;

sChannel.connect(new InetSocketAddress(inetAddr, portNumber));
Expand Down Expand Up @@ -4234,11 +4242,11 @@ private void writePacketHeader(int tdsMessageStatus) {
// length is 16
// bits,
stagingBuffer.put(TDS.PACKET_HEADER_MESSAGE_LENGTH + 1, (byte) ((tdsMessageLength >> 0) & 0xFF)); // written BIG
// ENDIAN
// ENDIAN
stagingBuffer.put(TDS.PACKET_HEADER_SPID, (byte) ((tdsChannel.getSPID() >> 8) & 0xFF)); // Note: SPID is 16
// bits,
stagingBuffer.put(TDS.PACKET_HEADER_SPID + 1, (byte) ((tdsChannel.getSPID() >> 0) & 0xFF)); // written BIG
// ENDIAN
// ENDIAN
stagingBuffer.put(TDS.PACKET_HEADER_SEQUENCE_NUM, (byte) (packetNum % 256));
stagingBuffer.put(TDS.PACKET_HEADER_WINDOW, (byte) 0); // Window (Reserved/Not used)

Expand All @@ -4250,11 +4258,11 @@ private void writePacketHeader(int tdsMessageStatus) {
// length is 16
// bits,
logBuffer.put(TDS.PACKET_HEADER_MESSAGE_LENGTH + 1, (byte) ((tdsMessageLength >> 0) & 0xFF)); // written BIG
// ENDIAN
// ENDIAN
logBuffer.put(TDS.PACKET_HEADER_SPID, (byte) ((tdsChannel.getSPID() >> 8) & 0xFF)); // Note: SPID is 16
// bits,
logBuffer.put(TDS.PACKET_HEADER_SPID + 1, (byte) ((tdsChannel.getSPID() >> 0) & 0xFF)); // written BIG
// ENDIAN
// ENDIAN
logBuffer.put(TDS.PACKET_HEADER_SEQUENCE_NUM, (byte) (packetNum % 256));
logBuffer.put(TDS.PACKET_HEADER_WINDOW, (byte) 0); // Window (Reserved/Not used);
}
Expand Down Expand Up @@ -6418,7 +6426,13 @@ final class TDSReaderMark {
*
* Bytes are read from SQL Server into a FIFO of packets. Reader methods traverse the packets to access the data.
*/
final class TDSReader {
final class TDSReader implements Serializable {

/**
* Always update serialVersionUID when prompted.
*/
private static final long serialVersionUID = -392905303734809731L;

private static final Logger logger = Logger.getLogger("com.microsoft.sqlserver.jdbc.internals.TDS.Reader");
final private String traceID;
private ScheduledFuture<?> timeout;
Expand Down Expand Up @@ -7214,7 +7228,12 @@ final void trySetSensitivityClassification(SensitivityClassification sensitivity
* the interrupt event occurs when the timeout period expires. Currently, only the time to receive the response from the
* channel counts against the timeout period.
*/
abstract class TDSCommand {
abstract class TDSCommand implements Serializable {
/**
* Always update serialVersionUID when prompted.
*/
private static final long serialVersionUID = 5485075546328951857L;

abstract boolean doExecute() throws SQLServerException;

static final Logger logger = Logger.getLogger("com.microsoft.sqlserver.jdbc.internals.TDS.Command");
Expand Down Expand Up @@ -7800,6 +7819,11 @@ final TDSReader startResponse(boolean isAdaptive) throws SQLServerException {
* implementation for such commands.
*/
abstract class UninterruptableTDSCommand extends TDSCommand {
/**
* Always update serialVersionUID when prompted.
*/
private static final long serialVersionUID = -6457195977162963793L;

UninterruptableTDSCommand(String logContext) {
super(logContext, 0, 0);
}
Expand Down
Loading