Skip to content

Commit

Permalink
Fix bug on encoding saved tasks
Browse files Browse the repository at this point in the history
There were observations on different devices that the file duke.txt
containing saved tasks has a newline character at the beginning of the file.

Another observation seen is that there is no newline character after the first task
is encoded, causing the second task to be
written on the same line as the first task

The loadTask() function subsequently reads the line as a corrupted line.
Some reported issues relaunching the app.

This has been corrected and SeeWhyAre app should be launching normally.
  • Loading branch information
freddychenyouren2 committed Sep 22, 2023
1 parent 95125bd commit 985dc26
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
11 changes: 4 additions & 7 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
D | 0 | test dates correct deadline | 2023-10-21 | null
E | 0 | correct event timings | 2222-11-11 | 2222-11-13
D | 1 | Dead Package bruh | 1111-11-11 | null
T | 0 | After Checkstyle | null | null
D | 0 | VIEWSCHEDULE BRO | 2023-09-14 | null
E | 0 | MUGGING SESSION | 2023-09-10 | 2023-09-30
D | 0 | CS2100 assignment debug | 2023-09-17 | null
T | 0 | reset | null | null
T | 0 | another test | null | null
D | 0 | hndoa | 1111-11-11 | null
T | 0 | bjjkvd | null | null
7 changes: 5 additions & 2 deletions src/main/java/duke/util/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ public static void saveTask(Task task, boolean isAppend) throws IOException {
saved[1] = task.isDone ? "1" : "0";
saved[2] = task.getDescription();

bufferedWriter.write(String.join(" | ", saved));

if (isAppend) {
bufferedWriter.newLine();
}
bufferedWriter.write(String.join(" | ", saved));

bufferedWriter.close();
}

Expand Down Expand Up @@ -110,7 +112,7 @@ public void checkFile() {
} else {
System.out.println("System Message: File 'duke.txt' exists! Loading past data...");
}

if (!Files.exists(fileForTesting)) {
System.out.println("System Message: File 'taskListTest.txt' does not exist. Creating one..."
+ "You can view it under 'data' directory after exiting the program this time.");
Expand Down Expand Up @@ -139,6 +141,7 @@ public void loadTasks() throws IOException, InvalidDateException {
while ((currentLine = bufferedReader.readLine()) != null) {
if (!TaskList.isValidTaskLine(currentLine)) {
System.out.printf("Skipping corrupted line: %s\n", currentLine);
continue;
}
// Parse the line. Check which type of task it belongs to. Create task and put it in list of tasks.
String[] content = currentLine.split(" \\| ");
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/duke/util/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ protected String farewell() {
.append("\nBye bye. Please use me again soon!\n")
.append(printHorizontalLine());

printHorizontalLine();
printHorizontalLine();
scanner.close();
quitProgram();
Duke.setIsFinishedToTrue();
Expand Down

0 comments on commit 985dc26

Please sign in to comment.