Menu

#52 Config.append doesn't update the Config object

open
nobody
5
2007-12-31
2007-12-31
kxavier
No

JPF Version 4.1

The method append from the gov.nasa.jpf.Config doesn't work. The code is presented below:

public void append (String key, String value, String separator) {
String v = (String)get(key);
if (v != null) {
if (separator != null) {
v += separator;
}
v += value;
} else {
put(key,value);
}
}

Since String is a immutable Object, the operations on the variable v have no effect in the original Object, with the reference returned through the get(key) method. And since v is a local variable its value is lost on method return and no change is done to the config object.

So it is necessary to update the config object using the method put(key,v).

public void append (String key, String value, String separator) {
String v = (String)get(key);
if (v != null) {
if (separator != null) {
v += separator;
}
v += value;
//Added code
put(key,v);
} else {
put(key,value);
}
}

Discussion


Log in to post a comment.

MongoDB Logo MongoDB