Skip to content

Commit

Permalink
fix some warnnings in IOBuffer.java base on SonarQube
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyushawn committed May 16, 2017
1 parent 3488829 commit c4d9439
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3941,7 +3941,7 @@ void writeReader(Reader reader,
}

GregorianCalendar initializeCalender(TimeZone timeZone) {
GregorianCalendar calendar = null;
GregorianCalendar calendar;

// Create the calendar that will hold the value. For DateTimeOffset values, the calendar's
// time zone is UTC. For other values, the calendar's time zone is a local time zone.
Expand Down Expand Up @@ -5207,7 +5207,7 @@ void writeRPCDateTime(String sName,
int subSecondNanos,
boolean bOut) throws SQLServerException {
assert (subSecondNanos >= 0) && (subSecondNanos < Nanos.PER_SECOND) : "Invalid subNanoSeconds value: " + subSecondNanos;
assert (cal != null) || (cal == null && subSecondNanos == 0) : "Invalid subNanoSeconds value when calendar is null: " + subSecondNanos;
assert (cal != null) || (subSecondNanos == 0) : "Invalid subNanoSeconds value when calendar is null: " + subSecondNanos;

writeRPCNameValType(sName, bOut, TDSType.DATETIMEN);
writeByte((byte) 8); // max length of datatype
Expand Down Expand Up @@ -5347,7 +5347,7 @@ void writeEncryptedRPCDateTime(String sName,
boolean bOut,
JDBCType jdbcType) throws SQLServerException {
assert (subSecondNanos >= 0) && (subSecondNanos < Nanos.PER_SECOND) : "Invalid subNanoSeconds value: " + subSecondNanos;
assert (cal != null) || (cal == null && subSecondNanos == 0) : "Invalid subNanoSeconds value when calendar is null: " + subSecondNanos;
assert (cal != null) || (subSecondNanos == 0) : "Invalid subNanoSeconds value when calendar is null: " + subSecondNanos;

writeRPCNameValType(sName, bOut, TDSType.BIGVARBINARY);

Expand Down Expand Up @@ -6330,7 +6330,10 @@ synchronized final boolean readPacket() throws SQLServerException {

// Make header size is properly bounded and compute length of the packet payload.
if (packetLength < TDS.PACKET_HEADER_SIZE || packetLength > con.getTDSPacketSize()) {
logger.warning(toString() + " TDS header contained invalid packet length:" + packetLength + "; packet size:" + con.getTDSPacketSize());
if (logger.isLoggable(Level.WARNING)) {
logger.warning(
toString() + " TDS header contained invalid packet length:" + packetLength + "; packet size:" + con.getTDSPacketSize());
}
throwInvalidTDS();
}

Expand Down Expand Up @@ -6564,7 +6567,9 @@ final Object readDecimal(int valueLength,
JDBCType jdbcType,
StreamType streamType) throws SQLServerException {
if (valueLength > valueBytes.length) {
logger.warning(toString() + " Invalid value length:" + valueLength);
if (logger.isLoggable(Level.WARNING)) {
logger.warning(toString() + " Invalid value length:" + valueLength);
}
throwInvalidTDS();
}

Expand Down Expand Up @@ -7260,7 +7265,9 @@ final void close() {
// then assume that no attention ack is forthcoming from the server and
// terminate the connection to prevent any other command from executing.
if (attentionPending) {
logger.severe(this + ": expected attn ack missing or not processed; terminating connection...");
if (logger.isLoggable(Level.SEVERE)) {
logger.severe(this + ": expected attn ack missing or not processed; terminating connection...");

This comment has been minimized.

Copy link
@v-nisidh

v-nisidh May 16, 2017

Contributor

As you are touching this code can you use this.toString() instead of this

}

try {
tdsReader.throwInvalidTDS();
Expand Down Expand Up @@ -7586,6 +7593,8 @@ abstract class UninterruptableTDSCommand extends TDSCommand {
final void interrupt(String reason) throws SQLServerException {
// Interrupting an uninterruptable command is a no-op. That is,
// it can happen, but it should have no effect.
logger.finest(toString() + " Ignoring interrupt of uninterruptable TDS command; Reason:" + reason);
if (logger.isLoggable(Level.FINEST)) {
logger.finest(toString() + " Ignoring interrupt of uninterruptable TDS command; Reason:" + reason);
}
}
}

0 comments on commit c4d9439

Please sign in to comment.