Crash reports handle invalid format strings properly

This commit is contained in:
Sergey Karmanov 2020-11-15 23:11:46 +03:00
parent ccda1eff74
commit ec6181aaa8

View File

@ -43,6 +43,26 @@ public class CrashReports {
public static void report(Throwable throwable, String messageFormat, Object... args) {
StringBuilder output = new StringBuilder();
try {
String.format(messageFormat, args);
} catch (IllegalFormatException e) {
messageFormat = StringUtil.replaceAll(messageFormat, "%", "%%");
if (args.length != 0) {
messageFormat += "\nArgs:";
for (Object arg : args) {
try {
messageFormat += " \"" + arg.toString() + "\"";
} catch (Throwable t) {
messageFormat += " exc: \"" + t.getClass().toString() + "\"";
}
}
args = new Object[0]; // clear args
}
messageFormat += "\nCould not format provided description";
}
appendContextProviders(output);
addSeparator(output);
if (appendAnalyzers(output, throwable, messageFormat, args)) {