[GH-ISSUE #375] smssync_log file only ever has one line in it #270

Closed
opened 2026-02-28 01:23:57 +03:00 by kerem · 1 comment
Owner

Originally created by @alxndrsn on GitHub (Apr 6, 2016).
Original GitHub issue: https://github.com/ushahidi/SMSSync/issues/375

The file smssync_log is written to SD card by FileManager, which appears to be a singleton. Every append to FileManager in the current codebase calls FileManager.appendAndClose(), which closes the underlying PrintWriter. From the Java 7 JavaDoc, closing a PrintWriter multiple times will have no effect (the Android JavaDoc makes no mention of this). The effect of appending to a closed PrintWriter is not documented, but from experimentation it seems to have no effect. This may explain why this bug has not been noticed.

The obvious fix for this is to change all calls to appendAndClose() to append().

Originally created by @alxndrsn on GitHub (Apr 6, 2016). Original GitHub issue: https://github.com/ushahidi/SMSSync/issues/375 The file `smssync_log` is written to SD card by [`FileManager`](https://github.com/ushahidi/SMSSync/blob/master/smssync/src/main/java/org/addhen/smssync/data/cache/FileManager.java), which [appears to be a singleton](https://github.com/ushahidi/SMSSync/blob/master/smssync/src/main/java/org/addhen/smssync/presentation/di/module/AppModule.java#L63). Every append to `FileManager` in the current codebase calls [`FileManager.appendAndClose()`](https://github.com/ushahidi/SMSSync/blob/master/smssync/src/main/java/org/addhen/smssync/data/cache/FileManager.java#L239), which [closes the underlying `PrintWriter`](https://github.com/ushahidi/SMSSync/blob/master/smssync/src/main/java/org/addhen/smssync/data/cache/FileManager.java#L252). From the [Java 7 JavaDoc](https://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html#close%28%29), closing a `PrintWriter` multiple times will have no effect (the [Android JavaDoc makes no mention of this](https://developer.android.com/reference/java/io/PrintWriter.html#close%28%29)). The effect of appending to a closed `PrintWriter` is not documented, but from experimentation it seems to have no effect. This may explain why this bug has not been noticed. The obvious fix for this is to change all calls to `appendAndClose()` to `append()`.
kerem closed this issue 2026-02-28 01:23:57 +03:00
Author
Owner

@alxndrsn commented on GitHub (Apr 6, 2016):

Ah yes, from the PrintWriter docs:

No IOException is thrown by this class.
https://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html

<!-- gh-comment-id:206240213 --> @alxndrsn commented on GitHub (Apr 6, 2016): Ah yes, from the `PrintWriter` docs: > No `IOException` is thrown by this class. > – _https://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html_
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SMSSync#270
No description provided.