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 @Override
public String formatMessage(String theMessage, Object... theMessageArguments) { public String formatMessage(String theMessage, Object... theMessageArguments) {
String message; String message = theMessage;
if (theMessageArguments != null && theMessageArguments.length > 0) { if (Objects.nonNull(i18Nmessages) && i18Nmessages.containsKey(theMessage)) {
if (Objects.nonNull(theMessageArguments) && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments); message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else if (i18Nmessages.containsKey(theMessage)) {
message = i18Nmessages.getString(theMessage);
} else { } else {
message = theMessage; message = i18Nmessages.getString(theMessage);
}
} }
return message; return message;
} }

View File

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

View File

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

View File

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