Skip to content

Commit 878c4a1

Browse files
committed
CONJ-858 Properties parameter different than string not taken in account
``` Properties connProperties = new Properties(); connProperties.setProperty("useSSL", "true"); ``` is ok, but using the same as object will only be taken in account when value has a string value ``` Properties connProperties = new Properties(); connProperties.put("useSSL", true); ``` useSSL will not be enable, without any error.
1 parent 560c230 commit 878c4a1

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#dist: trusty
2-
sudo: false
1+
dist: xenial
32
language: java
43
services: docker
4+
os: linux
55
addons:
66
hosts:
77
- mariadb.example.com
@@ -22,7 +22,7 @@ cache:
2222
directories:
2323
- $HOME/.m2
2424

25-
matrix:
25+
jobs:
2626
allow_failures:
2727
- env: DB=build:10.6
2828
jdk: openjdk11

src/main/java/org/mariadb/jdbc/Configuration.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -438,19 +438,19 @@ private static void mapPropertiesToOption(Builder builder, Properties properties
438438
// loop on properties,
439439
// - check DefaultOption to check that property value correspond to type (and range)
440440
// - set values
441-
for (String key : properties.stringPropertyNames()) {
442-
String realKey = OptionAliases.OPTIONS_ALIASES.get(key);
443-
if (realKey == null) realKey = key;
444-
final String propertyValue = properties.getProperty(realKey);
441+
for (final Object keyObj : properties.keySet()) {
442+
String realKey = OptionAliases.OPTIONS_ALIASES.get(keyObj);
443+
if (realKey == null) realKey = keyObj.toString();
444+
final Object propertyValue = properties.get(realKey);
445445

446-
if (propertyValue != null && !key.isEmpty()) {
446+
if (propertyValue != null && realKey != null) {
447447
try {
448448
final Field field = Builder.class.getDeclaredField(realKey);
449449
field.setAccessible(true);
450450
if (field.getGenericType().equals(String.class)) {
451451
field.set(builder, propertyValue);
452452
} else if (field.getGenericType().equals(Boolean.class)) {
453-
switch (propertyValue.toLowerCase()) {
453+
switch (propertyValue.toString().toLowerCase()) {
454454
case "":
455455
case "1":
456456
case "true":
@@ -466,22 +466,22 @@ private static void mapPropertiesToOption(Builder builder, Properties properties
466466
throw new IllegalArgumentException(
467467
String.format(
468468
"Optional parameter %s must be boolean (true/false or 0/1) was '%s'",
469-
key, propertyValue));
469+
keyObj, propertyValue));
470470
}
471471
} else if (field.getGenericType().equals(Integer.class)) {
472472
try {
473-
final Integer value = Integer.parseInt(propertyValue);
473+
final Integer value = Integer.parseInt(propertyValue.toString());
474474
field.set(builder, value);
475475
} catch (NumberFormatException n) {
476476
throw new IllegalArgumentException(
477477
String.format(
478-
"Optional parameter %s must be Integer, was '%s'", key, propertyValue));
478+
"Optional parameter %s must be Integer, was '%s'", keyObj, propertyValue));
479479
}
480480
}
481481
} catch (NoSuchFieldException nfe) {
482482
// keep unknown option:
483483
// those might be used in authentication or identity plugin
484-
nonMappedOptions.put(key, properties.getProperty(key));
484+
nonMappedOptions.put(keyObj, propertyValue);
485485
}
486486
}
487487
}

src/test/java/org/mariadb/jdbc/unit/util/ConfigurationTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,33 @@ public void testJdbcParserSimpleIpv4Properties() throws SQLException {
342342
Properties prop = new Properties();
343343
prop.setProperty("user", "greg");
344344
prop.setProperty("password", "pass");
345+
prop.setProperty("allowMultiQueries", "true");
345346

346347
Configuration conf = org.mariadb.jdbc.Configuration.parse(url, prop);
347348
assertEquals("database", conf.database());
348349
assertEquals("greg", conf.user());
349350
assertEquals("pass", conf.password());
351+
assertTrue(conf.allowMultiQueries());
350352
assertEquals(3, conf.addresses().size());
351353
assertEquals(HostAddress.from("master", 3306, true), conf.addresses().get(0));
352354
assertEquals(HostAddress.from("slave1", 3307, true), conf.addresses().get(1));
353355
assertEquals(HostAddress.from("slave2", 3308, true), conf.addresses().get(2));
356+
357+
prop = new Properties();
358+
prop.put("user", "greg");
359+
prop.put("password", "pass");
360+
prop.put("allowMultiQueries", true);
361+
362+
conf = org.mariadb.jdbc.Configuration.parse(url, prop);
363+
assertEquals("database", conf.database());
364+
assertEquals("greg", conf.user());
365+
assertEquals("pass", conf.password());
366+
assertTrue(conf.allowMultiQueries());
367+
assertEquals(3, conf.addresses().size());
368+
assertEquals(HostAddress.from("master", 3306, true), conf.addresses().get(0));
369+
assertEquals(HostAddress.from("slave1", 3307, true), conf.addresses().get(1));
370+
assertEquals(HostAddress.from("slave2", 3308, true), conf.addresses().get(2));
371+
354372
}
355373

356374
@Test

0 commit comments

Comments
 (0)