Skip to content

Commit

Permalink
[se-edu#264] Replace use of assert false with `throw new AssertionE…
Browse files Browse the repository at this point in the history
…rror()` (se-edu#788)

In some places of the code, we use `assert false` to indicate the
execution has reached an unacceptable state.

This is not compliant with our code style (as revised by [1]) which
states `throw new AssertionError()` is preferred for such situations.

Let's replace `assert false` with `throw new AssertionError()` where
applicable.

[1] oss-generic/process#19
  • Loading branch information
Zhiyuan-Amos authored Jan 8, 2018
2 parents 3a228ef + 659e5c2 commit 6b8ea09
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public CommandResult executeUndoableCommand() throws CommandException {
try {
model.deletePerson(personToDelete);
} catch (PersonNotFoundException pnfe) {
assert false : "The target person cannot be missing";
throw new AssertionError("The target person cannot be missing");
}

return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void resetData(ReadOnlyAddressBook newData) {
try {
setPersons(newData.getPersonList());
} catch (DuplicatePersonException e) {
assert false : "AddressBooks should not have duplicate persons";
throw new AssertionError("AddressBooks should not have duplicate persons");
}

setTags(new HashSet<>(newData.getTagList()));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/storage/XmlFileStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void saveDataToFile(File file, XmlSerializableAddressBook addressB
try {
XmlUtil.saveDataToFile(file, addressBook);
} catch (JAXBException e) {
assert false : "Unexpected exception " + e.getMessage();
throw new AssertionError("Unexpected exception " + e.getMessage());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/seedu/address/testutil/TypicalPersons.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static AddressBook getTypicalAddressBook() {
try {
ab.addPerson(person);
} catch (DuplicatePersonException e) {
assert false : "not possible";
throw new AssertionError("not possible");
}
}
return ab;
Expand Down

0 comments on commit 6b8ea09

Please sign in to comment.