Skip to content

Commit 7d2abd5

Browse files
committed
fix #2336: check for null text entry, replace them with a string
1 parent de4dac8 commit 7d2abd5

File tree

1 file changed

+27
-22
lines changed
  • WordPressUtils/src/main/java/org/wordpress/android/util

1 file changed

+27
-22
lines changed

WordPressUtils/src/main/java/org/wordpress/android/util/AppLog.java

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,31 @@ private String toHtmlColor() {
113113
}
114114

115115
private static class LogEntry {
116-
LogLevel logLevel;
117-
String logText;
118-
T logTag;
116+
LogLevel mLogLevel;
117+
String mLogText;
118+
T mLogTag;
119+
120+
public LogEntry(LogLevel logLevel, String logText, T logTag) {
121+
mLogLevel = logLevel;
122+
mLogText = logText;
123+
if (mLogText == null) {
124+
mLogText = "null";
125+
}
126+
mLogTag = logTag;
127+
}
119128

120129
private String toHtml() {
121-
StringBuilder sb = new StringBuilder()
122-
.append("<font color=\"")
123-
.append(logLevel.toHtmlColor())
124-
.append("\">")
125-
.append("[")
126-
.append(logTag.name())
127-
.append("] ")
128-
.append(logLevel.name())
129-
.append(": ")
130-
.append(TextUtils.htmlEncode(logText).replace("\n", "<br />"))
131-
.append("</font>");
130+
StringBuilder sb = new StringBuilder();
131+
sb.append("<font color=\"");
132+
sb.append(mLogLevel.toHtmlColor());
133+
sb.append("\">");
134+
sb.append("[");
135+
sb.append(mLogTag.name());
136+
sb.append("] ");
137+
sb.append(mLogLevel.name());
138+
sb.append(": ");
139+
sb.append(TextUtils.htmlEncode(mLogText).replace("\n", "<br />"));
140+
sb.append("</font>");
132141
return sb.toString();
133142
}
134143
}
@@ -155,12 +164,10 @@ private void removeFirstEntry() {
155164

156165
private static void addEntry(T tag, LogLevel level, String text) {
157166
// skip if recording is disabled (default)
158-
if (!mEnableRecording)
167+
if (!mEnableRecording) {
159168
return;
160-
LogEntry entry = new LogEntry();
161-
entry.logLevel = level;
162-
entry.logText = text;
163-
entry.logTag = tag;
169+
}
170+
LogEntry entry = new LogEntry(level, text, tag);
164171
mLogEntries.addEntry(entry);
165172
}
166173

@@ -170,7 +177,6 @@ private static String getStringStackTrace(Throwable throwable) {
170177
return errors.toString();
171178
}
172179

173-
174180
/*
175181
* returns entire log as html for display (see AppLogViewerActivity)
176182
*/
@@ -188,7 +194,6 @@ public static ArrayList<String> toHtmlList(Context context) {
188194
return items;
189195
}
190196

191-
192197
/*
193198
* returns entire log as plain text
194199
*/
@@ -203,7 +208,7 @@ public static String toPlainText(Context context) {
203208
int lineNum = 1;
204209
while (it.hasNext()) {
205210
sb.append(String.format("%02d - ", lineNum))
206-
.append(it.next().logText)
211+
.append(it.next().mLogText)
207212
.append("\n");
208213
lineNum++;
209214
}

0 commit comments

Comments
 (0)