Bug 640 - Java Null Exception when view the Application that is empty
Summary: Java Null Exception when view the Application that is empty
Status: RESOLVED FIXED
Alias: None
Product: 2021 CS3343 Hall Admission System
Classification: Unclassified
Component: System Section (show other bugs)
Version: unspecified
Hardware: PC Windows
: Normal minor
Assignee: Azim
URL:
Depends on:
Blocks:
 
Reported: 2021-12-04 16:01 HKT by amble3232
Modified: 2021-12-04 16:06 HKT (History)
2 users (show)

See Also:


Attachments

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