Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,7 @@ shadowJar {

run {
standardInput = System.in
// Java ignores assert statements unless told otherwise, so turn them on when
// running the app from Gradle. Tests already run with assertions on.
enableAssertions = true
}
1 change: 1 addition & 0 deletions src/main/java/ted/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void setTed(Ted ted) {
*/
@FXML
private void handleUserInput() {
assert ted != null : "Main calls setTed before showing the window, so input always has a Ted";
String input = userInput.getText();
String response = ted.getResponse(input);
if (response.isEmpty()) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ted/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ private Parser() {
* @throws TedException if the command is unknown or its details are unusable.
*/
public static Command parse(String input) throws TedException {
assert !input.isBlank() : "Ted skips blank input, so it never reaches the parser";

// Splitting into at most two parts keeps the command word exact, so that
// "todos" is not mistaken for "todo", while leaving the rest untouched.
String[] parts = input.split(" ", 2);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ted/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ public int getSkippedLineCount() {
* @return the rebuilt task, or {@code null} if the line is not in the expected format.
*/
private static Task parseLine(String line) {
assert !line.isBlank() : "load() skips blank lines, so they are never parsed";

// A first, unlimited split just to read the type icon safely: even a
// corrupted line must have at least its icon before anything can be parsed.
String icon = line.split(FIELD_SEPARATOR_REGEX)[0];
Expand Down Expand Up @@ -172,7 +174,7 @@ private static Task parseLine(String line) {
parseSavedDateTime(fields[3])),
isDone);
default:
// Unreachable: fieldCountFor accepts only T, D and E.
assert false : "unreachable, as fieldCountFor accepts only T, D and E";
return null;
}
} catch (DateTimeParseException e) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ted/Ted.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public String getResponse(String input) {
return ui.flush();
}

assert tasks != null : "the constructor sets up a task list even when loading fails";
try {
command.execute(tasks, ui, storage);
} catch (TedException e) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ted/task/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public TaskList() {
* @param tasks the tasks to start with.
*/
public TaskList(List<Task> tasks) {
assert tasks.stream().allMatch(task -> task != null) : "Storage.load() never adds null";
this.tasks = new ArrayList<>(tasks);
}

Expand Down