Skip to content

Commit

Permalink
Added a null check in IOBuffer + addressed SonarQube comments. (#2145)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffery-Wasty authored Jun 8, 2023
1 parent 73d4581 commit 8b3b22d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
*/
final class ActivityCorrelator {

private static ActivityId s_ActivityId;
private static ActivityId activityId;
private static Lock lockObject = new ReentrantLock();

// Get the current ActivityId in TLS
static ActivityId getCurrent() {
if (s_ActivityId == null) {
if (activityId == null) {
lockObject.lock();
if (s_ActivityId == null) {
s_ActivityId = new ActivityId();
if (activityId == null) {
activityId = new ActivityId();
}
lockObject.unlock();
}

return s_ActivityId;
return activityId;
}

// Increment the Sequence number of the ActivityId in TLS
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6876,7 +6876,7 @@ final boolean readPacket() throws SQLServerException {
}

// if messageType is RPC or QUERY, then increment Counter's state
if (tdsChannel.getWriter().checkIfTdsMessageTypeIsBatchOrRPC()) {
if (tdsChannel.getWriter().checkIfTdsMessageTypeIsBatchOrRPC() && null != command) {
command.getCounter().increaseCounter(packetLength);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3703,10 +3703,8 @@ void prelogin(String serverName, int portNumber) throws SQLServerException {
Util.writeInt((int) seqNum, preloginRequest, offset);
offset += 4;

if (Util.isActivityTraceOn()) {
if (connectionlogger.isLoggable(Level.FINER)) {
connectionlogger.finer(toString() + " ActivityId " + activityId.toString());
}
if (Util.isActivityTraceOn() && connectionlogger.isLoggable(Level.FINER)) {
connectionlogger.finer(toString() + " ActivityId " + activityId);
}

if (connectionlogger.isLoggable(Level.FINER)) {
Expand Down

0 comments on commit 8b3b22d

Please sign in to comment.