You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With version 5.1.0 the method copyStateTo() does a simple fields assignment from one HikariConfig object (A) to another (B) through java reflection. I'm assuming expected bahaviour of this method is to keep config A intact, i.e. as a default.
The unexpected result of field.set(other, field.get(this)); is that object references are getting passed, instead cloned instances.
This means, that changes done to i.e. config B dataSourceProperties (java.util.Properties) are reflected back to config A, which should remain intact. It leads to mixed properties for different sources. Please make it more reliable, or note this within documentation ;)
Here's custom copyStateTo() for config Properties fields:
// defaultConfig.copyStateTo(config);
// custom copy
for (var field : HikariConfig.class.getDeclaredFields()) {
if (!Modifier.isFinal(field.getModifiers()) && field.trySetAccessible()) {
try {
Object value = field.get(defaultConfig);
if (field.getType() == Properties.class) {
field.set(config, new Properties((Properties) value));
} else {
field.set(config, value);
}
} catch (Exception e) {
throw new RuntimeException("Failed to copy HikariConfig state: " + e.getMessage(), e);
}
}
}
The text was updated successfully, but these errors were encountered:
With version 5.1.0 the method copyStateTo() does a simple fields assignment from one HikariConfig object (A) to another (B) through java reflection. I'm assuming expected bahaviour of this method is to keep config A intact, i.e. as a default.
The unexpected result of
field.set(other, field.get(this));
is that object references are getting passed, instead cloned instances.This means, that changes done to i.e. config B dataSourceProperties (java.util.Properties) are reflected back to config A, which should remain intact. It leads to mixed properties for different sources. Please make it more reliable, or note this within documentation ;)
Here's custom copyStateTo() for config Properties fields:
The text was updated successfully, but these errors were encountered: