HHH-14316 Avoid accessing state in DriverManagerConnectionProviderImpl if null

This commit is contained in:
Guillaume Smet 2020-11-09 15:15:37 +01:00 committed by Sanne Grinovero
parent 1c6e2b4efb
commit a393cbd7f5
1 changed files with 12 additions and 2 deletions

View File

@ -168,11 +168,17 @@ public class DriverManagerConnectionProviderImpl
@Override
public Connection getConnection() throws SQLException {
if ( state == null ) {
throw new IllegalStateException( "Cannot get a connection as the driver manager is not properly initialized" );
}
return state.getConnection();
}
@Override
public void closeConnection(Connection conn) throws SQLException {
if ( state == null ) {
throw new IllegalStateException( "Cannot close a connection as the driver manager is not properly initialized" );
}
state.closeConnection( conn );
}
@ -204,13 +210,17 @@ public class DriverManagerConnectionProviderImpl
@Override
public void stop() {
state.stop();
if ( state != null ) {
state.stop();
}
}
//CHECKSTYLE:START_ALLOW_FINALIZER
@Override
protected void finalize() throws Throwable {
state.stop();
if ( state != null ) {
state.stop();
}
super.finalize();
}
//CHECKSTYLE:END_ALLOW_FINALIZER