Exporter: Arabic mojibake in Excel (missing UTF-8 BOM), cursor leak, and potential NPE #3
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
Review of
Exporter.ktidentified several reliability and usability issues with CSV exporting:Arabic Text Corrupted in Microsoft Excel (Missing BOM):
The CSV is written in standard UTF-8 without a Byte Order Mark (
). When opening the exported CSV in Microsoft Excel, Excel defaults to legacy ANSI/system encodings, rendering Arabic questions and demographic text as unreadable Mojibake (العربية). Writingat the start of the file resolves this across all spreadsheet software.Cursor Leak on Exception:
In
Exporter.export():If an exception occurs during file creation or writer allocation,
cursoris never closed.Potential NPE on
getExternalFilesDir(null):If external storage is unavailable or unmounted,
context.getExternalFilesDir(null)can returnnull, causingFile(null, fileName)to throw an uncaught exception.Incomplete CSV Escaping:
escapeCsv()checks for,,", and, but does not check for carriage return.Storage Leak / File Accumulation:
Each export creates a new timestamped file (
export_${System.currentTimeMillis()}.csv) in app storage without cleaning up previous exports.Suggested Fix
before writing the CSV header.cursor.useoutside the file writer.context.filesDirif external storage directory is null.inescapeCsv().