Fix set preferences REST handler for partially filled input record

It was erroneously assumed, that all attributes for input record are
always filled. This may not be the case. When input record only
partially filled, the current settings must be read from the git
backend, without nullifying false values and merged with partially
filled input record. Only after this merging new values can be written
to the git backend.

Change-Id: Iff5763fd408918622d6e82ac122bf09a99d9aaba
This commit is contained in:
David Ostrovsky
2015-10-29 22:54:24 +01:00
committed by Edwin Kempin
parent 494af1d177
commit ddd8ec8d06
5 changed files with 61 additions and 8 deletions

View File

@@ -314,19 +314,19 @@ public class ConfigUtil {
* The loading is performed eagerly: all values are set.
* <p>
* Fields marked with final or transient modifiers are skipped.
* <p>
* Boolean fields are only set when their values are true.
*
* @param cfg config from which the values are loaded
* @param section section
* @param sub subsection
* @param s instance of class in which the values are set
* @param defaults instance of class with default values
* @param i instance to merge during the load. When present, the
* boolean fields are not nullified when their values are false
* @return loaded instance
* @throws ConfigInvalidException
*/
public static <T> T loadSection(Config cfg, String section, String sub,
T s, T defaults) throws ConfigInvalidException {
T s, T defaults, T i) throws ConfigInvalidException {
try {
for (Field f : s.getClass().getDeclaredFields()) {
if (skipField(f)) {
@@ -345,7 +345,7 @@ public class ConfigUtil {
f.set(s, cfg.getLong(section, sub, n, (Long) d));
} else if (isBoolean(t)) {
boolean b = cfg.getBoolean(section, sub, n, (Boolean) d);
if (b) {
if (b || i != null) {
f.set(s, b);
}
} else if (t.isEnum()) {
@@ -353,6 +353,12 @@ public class ConfigUtil {
} else {
throw new ConfigInvalidException("type is unknown: " + t.getName());
}
if (i != null) {
Object o = f.get(i);
if (o != null) {
f.set(s, o);
}
}
}
} catch (SecurityException | IllegalArgumentException
| IllegalAccessException e) {