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

Added a null check in IOBuffer + addressed SonarQube comments. #2145

Merged
merged 1 commit into from
Jun 8, 2023
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 @@ -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