microsoft/mssql-jdbc

SQLServerStatement#executeCommand missing null check on SQLServerException#getCause.

jesperah opened this issue · 1 comments

Problem description

SQLServerException might have a null cause, causing the inner most exception to be lost when wrapping and re-throwing exception.

See SQLServerStatement line 264.

public class SQLServerStatement implements ISQLServerStatement {

...

    final void executeStatement(TDSCommand newStmtCmd) throws SQLServerException, SQLTimeoutException {
    ....
        catch (SQLServerException e) {
            if (e.getDriverErrorCode() == SQLServerException.ERROR_QUERY_TIMEOUT)
                throw new SQLTimeoutException(e.getMessage(), e.getSQLState(), e.getErrorCode(), e.getCause()); // e.getCause() might be null.
            else
                throw e;
        }
    ....
}

if e does not have a cause then e the inner most exception is lost.

Expected behavior

caught exception is preserved as cause of new re-thrown exception.

Actual behavior

if exception does not have an inner exception then null is passed as the cause of the re-thrown exception. and the inner most exception is lost.

thanks for reporting the issue and creating the PR, we will get that review and merged soon.