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

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

Closed
jesperah opened this issue Jan 15, 2024 · 1 comment · Fixed by #2300
Closed
Milestone

Comments

@jesperah
Copy link
Contributor

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.

@lilgreenbird
Copy link
Contributor

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

@Jeffery-Wasty Jeffery-Wasty linked a pull request Jan 15, 2024 that will close this issue
lilgreenbird pushed a commit that referenced this issue Jan 15, 2024
if the caught exception does not have a cause then pass the caught exception as the cause to the SQLTimeoutException instead of the null "e.getCause()". (#2299)

Co-authored-by: jesperah <[email protected]>
@github-project-automation github-project-automation bot moved this to Closed Issues in MSSQL JDBC Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed Issues
Development

Successfully merging a pull request may close this issue.

2 participants