Skip to content

Commit

Permalink
Squash bugs
Browse files Browse the repository at this point in the history
Program crashes due to null exception because logic in isValid is incorrect.
Fixed to avoid this issue.
  • Loading branch information
zupey committed Sep 14, 2022
1 parent 9f14bf0 commit 5a062b8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/duke/commands/CommandDeadlineHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public CommandDeadlineHandler(String value, String flag, String additionalValue)
* @throws DukeException error message.
*/
public void checkValid() throws DukeException {
boolean isValid = value == null || !flag.equals("by") || additionalValue == null;
if (isValid) {
boolean isInvalid = value == null || flag == null || !flag.equals("by") || additionalValue == null;
if (isInvalid) {
throw new InvalidSyntaxException("Correct usage: deadline return book /by 24/04/2019 1600");
}
assert !value.contains("|");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/commands/CommandEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public CommandEventHandler(String value, String flag, String additionalValue) th
* @throws DukeException error message.
*/
public void checkValid() throws DukeException {
boolean isValid = value == null || !flag.equals("at") || additionalValue == null;
if (isValid) {
boolean isInvalid = value == null || flag == null || !flag.equals("at") || additionalValue == null;
if (isInvalid) {
throw new InvalidSyntaxException("Correct usage: event dinner /at 24/04/2019 1600");
}
assert !value.contains("|");
Expand Down

0 comments on commit 5a062b8

Please sign in to comment.