Bug 526 - [CustomerOrder] java.lang.NullPointerException occurs when trying to get the dish duration from the Dish class
Summary: [CustomerOrder] java.lang.NullPointerException occurs when trying to get the ...
Status: CONFIRMED
Alias: None
Product: Group 25
Classification: Unclassified
Component: Bug (show other bugs)
Version: unspecified
Hardware: PC Windows
: --- enhancement
Assignee: yingtng4-c
URL:
Depends on:
Blocks:
 
Reported: 2020-12-06 20:06 HKT by Poon Ting Kwok
Modified: 2020-12-06 20:06 HKT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Poon Ting Kwok 2020-12-06 20:06:22 HKT
I am using Windows 10, with eclipse IDE version 2020-09, when I run the main code, a null pointer exception occurs when the kitchenProcess function in the main code is executed.

The null pointer exception actually originated in the Dish class. Since the dish class is null, therefore Dish.getDishDuration() cannot be invoked. The dish duration is needed in the calculation of the total time needed to process the orders. The total time is needed when assigning orders to chefs.

I checked the Main_02.txt (the file with the orders) and the SampleMenu1.txt and discovered that some dishes mentioned in the Main_02.txt does not appears in the menu. Since all the dishes written in the menu are loaded into the HashMap, when there are new dish names appears in the order, the HashMap will return a null object instead of a Dish class, but the program haven't handled this issue well.


Here is the content of the SampleMenu1.txt

beef,1,10,50
cake,0,5,10

Here is the content of the Main_02.txt

0/crackers;beef,beef,fish;cake
5/crackers;fish;cake
3/crackers;beef,fish;cake
4/crackers;;cake
7/crackers;fish,beef,beef;cake

Here is the complete trace.

java.lang.NullPointerException: Cannot invoke "Cusine.Dish.getDishDuration()" because the return value of "java.util.ArrayList.get(int)" is null
	at Order.CustomerOrder.getTimeTaken(CustomerOrder.java:72)
	at Persons.Chef.assignOrder(Chef.java:28)
	at Kitchen.Kitchen.process(Kitchen.java:35)
	at MainSystem.Main.kitchenProcess(Main.java:25)
	at SystemTest.SystemTest_MainSystem.SystemTest_Main_02(SystemTest_MainSystem.java:62)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
	at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:43)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
	at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:82)
	at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:73)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:141)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:98)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)