Crash reports handle invalid format strings properly
This commit is contained in:
parent
ccda1eff74
commit
ec6181aaa8
@ -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)) {
|
||||
|
Reference in New Issue
Block a user