diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java index e5e175b9e..1597d0cd3 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java @@ -6912,6 +6912,15 @@ final boolean readPacket() throws SQLServerException { // if messageType is RPC or QUERY, then increment Counter's state if (tdsChannel.getWriter().checkIfTdsMessageTypeIsBatchOrRPC() && null != command) { + if (logger.isLoggable(Level.FINER)) { + logger.warning(toString() + ": increasing state of counter for TDS Command: " + command.toString()); + } + + if (null == command.getCounter()) { + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_NullValue")); + Object[] msgArgs1 = {"TDS command counter"}; + throw new SQLServerException(form.format(msgArgs1), null); + } command.getCounter().increaseCounter(packetLength); }