Crash reports handle invalid format strings properly
This commit is contained in:
@@ -43,6 +43,26 @@ public class CrashReports {
|
|||||||
public static void report(Throwable throwable, String messageFormat, Object... args) {
|
public static void report(Throwable throwable, String messageFormat, Object... args) {
|
||||||
StringBuilder output = new StringBuilder();
|
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);
|
appendContextProviders(output);
|
||||||
addSeparator(output);
|
addSeparator(output);
|
||||||
if (appendAnalyzers(output, throwable, messageFormat, args)) {
|
if (appendAnalyzers(output, throwable, messageFormat, args)) {
|
||||||
|
Reference in New Issue
Block a user