| Summary: | Undo command crashes the program when there are no actions to undo | ||
|---|---|---|---|
| Product: | Group 4 | Reporter: | kykao2-c |
| Component: | Main | Assignee: | aaronlii2-c |
| Status: | IN_PROGRESS --- | ||
| Severity: | major | CC: | chlam286-c, kykao2-c, plchan83-c, sharitsang97 |
| Priority: | Normal | ||
| Version: | unspecified | ||
| Hardware: | PC | ||
| OS: | Mac OS | ||
| Deadline: | 2020-11-14 | ||
| Attachments: | Program crashed when using the undo command | ||
Bug fixed. Code for preventing the array out-of-bound exception problem is added as follows:
if (!undoList.isEmpty()) {
//undo a command
} else {
System.out.println("Nothing to undo.");
}
- Aaron
|
Created attachment 62 [details] Program crashed when using the undo command The program crashed upon the "undo" command when there is nothing to undo. Severity: Major. Priority: Normal. Specification of the device which encountered this problem: Macbook Pro 2017, 13-inch MacOS: Mojave version 10.14.6 Processor: 2.3 GHz Intel Core i5 Memory: 16 GB 2133 MHz LPDDR3 Graphics: Intel Iris Plus Graphics 640 1536 MB Steps to reproduce the bug: input: 1. "undo" output: Exception in thread "main" java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 0 at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248) at java.base/java.util.Objects.checkIndex(Objects.java:372) at java.base/java.util.ArrayList.remove(ArrayList.java:535) at managementSystem.RecordedCommand.undo(RecordedCommand.java:17) at managementSystem.CommandHandler.handle(CommandHandler.java:108) at managementSystem.Main.main(Main.java:20) Process finished with exit code 1 Observation: "undo" on empty arraylist accesses an invalid index and produces exception, which breaks the program. Expectation: The program returns an error message and asks the user to enter a new input without breaking the program whenever an undo command is used under the circumstance that there is nothing to undo. Expected output: Setting: there is nothing to undo. input: "undo" output: "Nothing to undo." The program does not end and the user should be able to enter any other input afterwards. Solution: Ensure the program does not access the invalid array index bound, eg. -1.