Skip to content

Commit

Permalink
Prevent ContainerDatabaseDriver from throwing NPEs when on classpath …
Browse files Browse the repository at this point in the history
…but not initialized (#3976)

When ContainerDatabaseDriver hasn't been used yet to connect, the delegate is null. This causes various JDBC metadata methods of the driver to fail with a NullPointerException. Prevent this by providing reasonable defaults.
  • Loading branch information
mrotteveel committed Apr 11, 2021
1 parent 1e6deb1 commit 9183f8f
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,27 +230,30 @@ private void runInitFunctionIfRequired(final ConnectionUrl connectionUrl, Connec

@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
return delegate.getPropertyInfo(url, info);
return delegate != null ? delegate.getPropertyInfo(url, info) : new DriverPropertyInfo[0];
}

@Override
public int getMajorVersion() {
return delegate.getMajorVersion();
return delegate != null ? delegate.getMajorVersion() : 1;
}

@Override
public int getMinorVersion() {
return delegate.getMinorVersion();
return delegate != null ? delegate.getMinorVersion() : 0;
}

@Override
public boolean jdbcCompliant() {
return delegate.jdbcCompliant();
return delegate != null && delegate.jdbcCompliant();
}

@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
return delegate.getParentLogger();
if (delegate != null) {
return delegate.getParentLogger();
}
throw new SQLFeatureNotSupportedException("getParentLogger not supported");
}

/**
Expand Down

0 comments on commit 9183f8f

Please sign in to comment.