Bug 495 - Program crash on inputs with incorrect arguments
Summary: Program crash on inputs with incorrect arguments
Status: RESOLVED FIXED
Alias: None
Product: Group 4
Classification: Unclassified
Component: Main (show other bugs)
Version: unspecified
Hardware: Macintosh Mac OS
: Highest critical
Deadline: 2020-11-05
Assignee: Paton
URL:
Depends on:
Blocks:
 
Reported: 2020-11-28 16:28 HKT by kykao2-c
Modified: 2020-11-28 16:39 HKT (History)
4 users (show)

See Also:


Attachments
Program crashed upon incorrect input arguments (65.91 KB, image/png)
2020-11-28 16:28 HKT, kykao2-c
Details

Note You need to log in before you can comment on or make changes to this bug.
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