Skip to content

SQLServerStatement#executeCommand missing null check on SQLServerException#getCause. #2299

@jesperah

Description

@jesperah

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Closed Issues

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions