Skip to content

Commit

Permalink
Fix SQLiteAppender in release builds (#179)
Browse files Browse the repository at this point in the history
Release builds that contain no debug info for stack traces
result in nulls for caller data, causing SQLiteAppender to
attempt INSERT statements with illegal null values.

This patch null-checks those INSERT-bindings to avoid the
exception and allow existing debug-enabled apps to log caller
data to the database.
  • Loading branch information
tony19 committed May 19, 2018
1 parent 7cae3a1 commit aab6361
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,20 @@ private void bindCallerData(SQLiteStatement stmt, StackTraceElement[] callerData
if (callerDataArray != null && callerDataArray.length > 0) {
StackTraceElement callerData = callerDataArray[0];
if (callerData != null) {
stmt.bindString(CALLER_FILENAME_INDEX, callerData.getFileName());
stmt.bindString(CALLER_CLASS_INDEX, callerData.getClassName());
stmt.bindString(CALLER_METHOD_INDEX, callerData.getMethodName());
stmt.bindString(CALLER_LINE_INDEX, Integer.toString(callerData.getLineNumber()));
bindString(stmt, CALLER_FILENAME_INDEX, callerData.getFileName());
bindString(stmt, CALLER_CLASS_INDEX, callerData.getClassName());
bindString(stmt, CALLER_METHOD_INDEX, callerData.getMethodName());
bindString(stmt, CALLER_LINE_INDEX, Integer.toString(callerData.getLineNumber()));
}
}
}

private void bindString(SQLiteStatement stmt, int columnIndex, String value) {
if (value != null) {
stmt.bindString(columnIndex, value);
}
}

/**
* Inserts an exception into the logging_exceptions table
*
Expand Down

0 comments on commit aab6361

Please sign in to comment.