Add fallback to support old not updated clients

If a updated client makes a param change request old client do not
recognize that enum. To avoid exceptions ro null pointers we fall back
to the UNDEFINED enum entry if available. As param value we show an empty
string.
Beside that issue no problems have been found so far with adding a new
param entry.
This commit is contained in:
Manfred Karrer 2019-01-30 00:05:07 +01:00
parent adad426797
commit a10ce23145
No known key found for this signature in database
GPG key ID: 401250966A6B2C46
2 changed files with 6 additions and 4 deletions

View file

@ -69,9 +69,10 @@ public class ProtoUtil {
E result = Enums.getIfPresent(enumType, name).orNull();
if (result == null) {
log.error("Invalid value for enum " + enumType.getSimpleName() + ": " + name);
// TODO returning null here can cause problems in caller. Maybe we should throw an exception? Or maybe
// better to ensure that enums have always a default value with represents an undefined state and we fall
// back to that.
result = Enums.getIfPresent(enumType, "UNDEFINED").orNull();
log.error("We try to lookup for an enum entry with name 'UNDEFINED' and use that if available, " +
"otherwise the enum is null. enum={}", result);
return result;
}
return result;
}

View file

@ -145,7 +145,8 @@ public class BsqFormatter extends BSFormatter {
public String formatParamValue(Param param, String value) {
switch (param.getParamType()) {
case UNDEFINED:
throw new IllegalArgumentException("ParamType UNDEFINED. param: " + param);
// In case we add a new param old clients will not know that enum and fall back to UNDEFINED.
return "";
case BSQ:
return formatCoinWithCode(parseToCoin(value));
case BTC: