Skip to content

Commit 1d28487

Browse files
authored
Fix NPE in generic connection init path (#633)
1 parent b282bd7 commit 1d28487

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

vertx-sql-client/src/main/java/io/vertx/sqlclient/SqlConnectOptions.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class SqlConnectOptions extends NetClientOptions {
3737
private boolean cachePreparedStatements = DEFAULT_CACHE_PREPARED_STATEMENTS;
3838
private int preparedStatementCacheMaxSize = DEFAULT_PREPARED_STATEMENT_CACHE_MAX_SIZE;
3939
private int preparedStatementCacheSqlLimit = DEFAULT_PREPARED_STATEMENT_CACHE_SQL_LIMIT;
40-
private Map<String, String> properties;
40+
private Map<String, String> properties = new HashMap<>(4);
4141

4242
public SqlConnectOptions() {
4343
super();
@@ -60,7 +60,9 @@ public SqlConnectOptions(SqlConnectOptions other) {
6060
this.cachePreparedStatements = other.cachePreparedStatements;
6161
this.preparedStatementCacheMaxSize = other.preparedStatementCacheMaxSize;
6262
this.preparedStatementCacheSqlLimit = other.preparedStatementCacheSqlLimit;
63-
this.properties = new HashMap<>(other.properties);
63+
if (other.properties != null) {
64+
this.properties = new HashMap<>(other.properties);
65+
}
6466
}
6567

6668
/**

vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/DriverTestBase.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,22 @@ public void testCreatePool04(TestContext ctx) {
107107
}));
108108
}
109109

110+
@Test
111+
public void testCreatePool05(TestContext ctx) {
112+
// The default options will be an instanceof the driver-specific class, so manually copy
113+
// each option over onto a fresh generic options object to force the generic constructor path
114+
SqlConnectOptions defaults = defaultOptions();
115+
SqlConnectOptions opts = new SqlConnectOptions()
116+
.setHost(defaults.getHost())
117+
.setPort(defaults.getPort())
118+
.setDatabase(defaults.getDatabase())
119+
.setUser(defaults.getUser())
120+
.setPassword(defaults.getPassword());
121+
Pool.pool(opts).getConnection(ctx.asyncAssertSuccess(ar -> {
122+
ar.close();
123+
}));
124+
}
125+
110126
@Test(expected = ServiceConfigurationError.class)
111127
public void testRejectCreatePool01(TestContext ctx) {
112128
Pool.pool(new BogusOptions());

0 commit comments

Comments
 (0)