Bug 640

Summary: Java Null Exception when view the Application that is empty
Product: 2021 CS3343 Hall Admission System Reporter: amble3232
Component: System SectionAssignee: Azim <mohamazim2>
Status: RESOLVED FIXED    
Severity: minor CC: chpang22-c, mohamazim2
Priority: Normal    
Version: unspecified   
Hardware: PC   
OS: Windows   

Description amble3232 2021-12-04 16:01:20 HKT
Background:
I am doing the unit test in ECLIPSE 2021-06 (4.20.0) on method viewApplication() in HallSystem class.
When I am doing testViewApplication2() in testHallSystem class, I am trying to test finding an std2’s application but there is no std2’ application.

Steps to Reproduce:
Run the package with testHall_Admission
Run the method “void testViewApplication2” in testHallSystem class

Actual result:
The system output the error message of “java.lang.NullPointerException: Cannot invoke “HallAdmissionSystem.Application.toString()” because the return value of “HallAdmissionSystem.HallSystem.findApplication(HallAdmissionSystem.Student)” is null” in the console after the test run.

Expected result:
I expected the system to output “null” or message of “No such student”.
Comment 1 newbie 2021-12-04 16:04:25 HKT
I just tried this test case, there is a null problem. I suspect the code forgot to take account of the null situation. The system shout just outputs empty if there is a null value.

I will pass it to the developer to solve this error.
Comment 2 Azim 2021-12-04 16:06:33 HKT
Currently, the system did not check if there is a null value, it run “Display.runDisplay("View Application", findApplication(std).toString(), false);” directly. Therefore, such errors appear when passing the null to the display object.

To solve the null error, the null value will be converted into an empty string.

Solution:
===============
public void viewApplication(Student std) {
	Application application = findApplication(std);
	if(application != null) {
		Display.runDisplay("View Application", findApplication(std).toString(), false);
	}
	else {
		System.out.println("");
	}
}