improved npe safety formatMessage method

This commit is contained in:
patrick-werner 2020-03-10 16:03:50 +01:00
parent 14a0f7d687
commit 7ada30807d
5 changed files with 393 additions and 248 deletions

View File

@ -425,13 +425,13 @@ public abstract class BaseWorkerContext implements IWorkerContext {
@Override
public String formatMessage(String theMessage, Object... theMessageArguments) {
String message;
if (theMessageArguments != null && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else if (i18Nmessages.containsKey(theMessage)) {
message = i18Nmessages.getString(theMessage);
} else {
message = theMessage;
String message = theMessage;
if (Objects.nonNull(i18Nmessages) && i18Nmessages.containsKey(theMessage)) {
if (Objects.nonNull(theMessageArguments) && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else {
message = i18Nmessages.getString(theMessage);
}
}
return message;
}

View File

@ -464,13 +464,13 @@ public abstract class BaseWorkerContext implements IWorkerContext {
@Override
public String formatMessage(String theMessage, Object... theMessageArguments) {
String message;
if (theMessageArguments != null && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else if (i18Nmessages.containsKey(theMessage)) {
message = i18Nmessages.getString(theMessage);
} else {
message = theMessage;
String message = theMessage;
if (Objects.nonNull(i18Nmessages) && i18Nmessages.containsKey(theMessage)) {
if (Objects.nonNull(theMessageArguments) && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else {
message = i18Nmessages.getString(theMessage);
}
}
return message;
}

View File

@ -1197,13 +1197,13 @@ public abstract class BaseWorkerContext implements IWorkerContext {
@Override
public String formatMessage(String theMessage, Object... theMessageArguments) {
String message;
if (theMessageArguments != null && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else if (i18Nmessages.containsKey(theMessage)) {
message = i18Nmessages.getString(theMessage);
} else {
message = theMessage;
String message = theMessage;
if (Objects.nonNull(i18Nmessages) && i18Nmessages.containsKey(theMessage)) {
if (Objects.nonNull(theMessageArguments) && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else {
message = i18Nmessages.getString(theMessage);
}
}
return message;
}

View File

@ -1297,13 +1297,13 @@ public abstract class BaseWorkerContext implements IWorkerContext {
@Override
public String formatMessage(String theMessage, Object... theMessageArguments) {
String message;
if (theMessageArguments != null && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else if (i18Nmessages.containsKey(theMessage)) {
message = i18Nmessages.getString(theMessage);
} else {
message = theMessage;
String message = theMessage;
if (Objects.nonNull(i18Nmessages) && i18Nmessages.containsKey(theMessage)) {
if (Objects.nonNull(theMessageArguments) && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else {
message = i18Nmessages.getString(theMessage);
}
}
return message;
}