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

View File

@ -168,11 +168,17 @@ private static Driver loadDriverIfPossible(String driverClassName, ServiceRegist
@Override @Override
public Connection getConnection() throws SQLException { 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(); return state.getConnection();
} }
@Override @Override
public void closeConnection(Connection conn) throws SQLException { 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 ); state.closeConnection( conn );
} }
@ -204,13 +210,17 @@ public <T> T unwrap(Class<T> unwrapType) {
@Override @Override
public void stop() { public void stop() {
if ( state != null ) {
state.stop(); state.stop();
} }
}
//CHECKSTYLE:START_ALLOW_FINALIZER //CHECKSTYLE:START_ALLOW_FINALIZER
@Override @Override
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
if ( state != null ) {
state.stop(); state.stop();
}
super.finalize(); super.finalize();
} }
//CHECKSTYLE:END_ALLOW_FINALIZER //CHECKSTYLE:END_ALLOW_FINALIZER