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

类AbstractStatementAdapter中close方法实现中clear顺序倒了 #394

Closed
IAmACoder opened this issue Sep 30, 2017 · 1 comment
Closed

Comments

@IAmACoder
Copy link

sharding-jdbc-core version-1.5.4.1
AbstractStatementAdapter方法实现中逐个close RoutedStatements集合前,先对集合做了clear操作,会导致RoutedStatements集合中的各个Statement的close方法执行不到。

目前的代码

@Override
public final void close() throws SQLException {
    closed = true;
    getRoutedStatements().clear();
    Collection<SQLException> exceptions = new LinkedList<>();
    for (Statement each : getRoutedStatements()) {
        try {
            each.close();
        } catch (final SQLException ex) {
            exceptions.add(ex);
        }
    }
    throwSQLExceptionIfNecessary(exceptions);
}

可以修改为:

public final void close() throws SQLException {
    closed = true;
    Collection<SQLException> exceptions = new LinkedList<>();
    for (Statement each : getRoutedStatements()) {
        try {
            each.close();
        } catch (final SQLException ex) {
            exceptions.add(ex);
        }
    }
    getRoutedStatements().clear();
    throwSQLExceptionIfNecessary(exceptions);
}
@terrymanu
Copy link
Member

fixed at 2.0.0.m1

terrymanu added a commit that referenced this issue Oct 9, 2017
@terrymanu terrymanu self-assigned this Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants