Skip to content

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

Closed
@IAmACoder

Description

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);
}

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions