Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DriverDataSource to not convert all provided property values to String. #1895

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/com/zaxxer/hikari/HikariConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,9 @@ private void logConfiguration()
if ("dataSourceProperties".equals(prop)) {
var dsProps = PropertyElf.copyProperties(dataSourceProperties);
dsProps.setProperty("password", "<masked>");
if (dsProps.containsKey("privateKey")) {
dsProps.setProperty("privateKey", "<masked>");
}
value = dsProps;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/hikari/HikariJNDIFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ synchronized public Object getObjectInstance(Object obj, Name name, Context name
var element = enumeration.nextElement();
var type = element.getType();
if (type.startsWith("dataSource.") || hikariPropSet.contains(type)) {
properties.setProperty(type, element.getContent().toString());
properties.put(type, element.getContent());
}
}
return createDataSource(properties, nameCtx);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/hikari/util/DriverDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public DriverDataSource(String jdbcUrl, String driverClassName, Properties prope
this.driverProperties = new Properties();

for (var entry : properties.entrySet()) {
driverProperties.setProperty(entry.getKey().toString(), entry.getValue().toString());
driverProperties.put(entry.getKey().toString(), entry.getValue());
}

if (username != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/hikari/util/PropertyElf.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static Object getProperty(final String propName, final Object target)
public static Properties copyProperties(final Properties props)
{
var copy = new Properties();
props.forEach((key, value) -> copy.setProperty(key.toString(), value.toString()));
props.forEach((key, value) -> copy.put(key.toString(), value));
return copy;
}

Expand Down
6 changes: 4 additions & 2 deletions src/test/java/com/zaxxer/hikari/pool/TestJNDI.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ public void testJndiLookup1() throws Exception
ref.add(new BogusRef("maxLifetime", "30000"));
ref.add(new BogusRef("maximumPoolSize", "10"));
ref.add(new BogusRef("dataSource.loginTimeout", "10"));
ref.add(new BogusRef("dataSource.nonStringObj", Integer.valueOf(10)));
Context nameCtx = new BogusContext();

try (HikariDataSource ds = (HikariDataSource) jndi.getObjectInstance(ref, null, nameCtx, null)) {
assertNotNull(ds);
assertEquals("foo", getUnsealedConfig(ds).getUsername());
assertEquals(ds.getDataSourceProperties().get("nonStringObj"), Integer.valueOf(10));
}
}

Expand Down Expand Up @@ -149,8 +151,8 @@ private class BogusRef extends RefAddr
{
private static final long serialVersionUID = 1L;

private String content;
BogusRef(String type, String content)
private Object content;
BogusRef(String type, Object content)
{
super(type);
this.content = content;
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/com/zaxxer/hikari/util/PropertyElfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,26 @@ public void setTargetFromPropertiesNotAClass() throws Exception
assertEquals("argument type mismatch", e.getCause().getMessage());
}
}

@Test
public void copyPropertiesPropValueIsString() {
Properties propertiesOrig = new Properties();
String stringPropName = "stringProp";
String stringPropValue = "aString";
propertiesOrig.setProperty(stringPropName, stringPropValue);

Properties propertiesCopy = PropertyElf.copyProperties(propertiesOrig);
assertEquals(stringPropValue, propertiesCopy.getProperty(stringPropName));
}

@Test
public void copyPropertiesPropValueIsNonStringObject() {
Properties propertiesOrig = new Properties();
String propName = "nonStringProp";
Integer propValue = 10;
propertiesOrig.put(propName, propValue);

Properties propertiesCopy = PropertyElf.copyProperties(propertiesOrig);
assertEquals(propValue, propertiesCopy.get(propName));
}
}