Bug 495

Summary: Program crash on inputs with incorrect arguments
Product: Group 4 Reporter: kykao2-c
Component: MainAssignee: Paton <plchan83-c>
Status: RESOLVED FIXED    
Severity: critical CC: aaronlii2-c, chlam286-c, kykao2-c, sharitsang97
Priority: Highest    
Version: unspecified   
Hardware: Macintosh   
OS: Mac OS   
Deadline: 2020-11-05   
Attachments: Program crashed upon incorrect input arguments

Description kykao2-c 2020-11-28 16:28:54 HKT
Created attachment 59 [details]
Program crashed upon incorrect input arguments

The program is immediately crashed upon an input containing incorrect arguments on my 2017 13-ich
Macbook Pro (OS: macOS Mojave; version 10.14.6). This error causes the program
unable to operate properly for normal usage.

Severity: Critical. 

Priority: Highest.

Specification of the device which encountered this problem:
MacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports)
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. "makePurchase a"
     or 2. "makePurchase a a a a"

output: 
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
	at managementSystem.CmdMakeTransaction.execute(CmdMakeTransaction.java:15)
	at managementSystem.CommandHandler.handle(CommandHandler.java:17)
	at managementSystem.Main.main(Main.java:20)

Observation:
The program crashes if the input contains incorrect argument information of the commands which exist in the system (e.g. correct type of arguments / insufficient arguments). The failure-causing inputs passed to parameters cannot be executed correctly and lead to an exception.

Expectation:
The program should ask the user to enter another command in a non-stop manner
instead of breaking a program due to the exception.

Expected Output:
input:  1. "makePurchase a"
output: 2. "Incorrect usage. Usage: "makePurchase [staffID] [customerID] [productID] [quantity]"."

Solution:
An input checking mechanism can be implemented for avoiding failure-causing
input to break the program. For example, check if the input fulfils the size of
arguments to be passed as well as to ensure it returns a error message to the
user without passing such input for retry instead.
Comment 1 Paton 2020-11-28 16:39:28 HKT
Bug fixed by adding a checking mechanism for invalid arguments.

The program is able to give the error message now.

- Paton