Bug 221 (error, handler, lacking, optimizing, path, the, when)

Summary: lacking error handler when optimizing the path
Product: Group 1 Reporter: WANG Ruochen <ruochwang2-c>
Component: CompanyAssignee: sherlockqiu
Status: RESOLVED FIXED    
Severity: critical CC: ruochwang2-c
Priority: High    
Version: v0.1-alpha   
Hardware: PC   
OS: Windows   
Attachments: source code of company

Description WANG Ruochen 2017-11-26 21:10:37 HKT
Created attachment 5 [details]
source code of company

when the destination is unreachable, the creation of the order raise error like below:
EMS$ Exception in thread "main" java.lang.NullPointerException
	at ems.Company.createOrder(Company.java:147)
	at ems.CmdCreateOrder.execute(CmdCreateOrder.java:19)
	at ems.Invoker.StoreAndExecute(Invoker.java:10)
	at ems.Main.main(Main.java:84)

the reproducing procedure:
0/login as manager
1/add and link branches
2/add customers
3/logout and login as one of the customer
4/create order to unreachable branch

expected output: "it is unreachable"
actual output: 
EMS$ Exception in thread "main" java.lang.NullPointerException
	at ems.Company.createOrder(Company.java:147)
	at ems.CmdCreateOrder.execute(CmdCreateOrder.java:19)
	at ems.Invoker.StoreAndExecute(Invoker.java:10)
	at ems.Main.main(Main.java:84)

The specific input and output in between
Express Company Manager super (level:0) created!
manager 0
EMS$ Log in as: Manager: 0 name: super
addManager qr 123456 male 1
EMS# Express Company Manager qr (level:1) created!
Manager: 1 name: qr is added by Manager: 0 name: super
addCustomer c1 123456 1 2 2
EMS# [Customer: 0 name: c1] is added by: Manager: 0 name: super
addCustomer c2 123456 1 16 16
EMS# [Customer: 1 name: c2] is added by: Manager: 0 name: super
addcustomer c3 123456 1 1 20
EMS# Cmd not found m
addCustomer c3 123456 1 1 20
EMS# [Customer: 2 name: c3] is added by: Manager: 0 name: super
logout
EMS# manager 1
EMS$ Log in as: Manager: 1 name: qr
addManager wfz 123456 male 1
EMS$ Cmd not found m
addBranch A 1 1
EMS$ Branch: ID: 1, Name: A, Position: (1, 1) is added by: Manager: 1 name: qr
addBranch B 13 14
EMS$ Branch: ID: 2, Name: B, Position: (13, 14) is added by: Manager: 1 name: qr
addBranch C 2 20
EMS$ Branch: ID: 3, Name: C, Position: (2, 20) is added by: Manager: 1 name: qr
addBranch D 5 5
EMS$ Branch: ID: 4, Name: D, Position: (5, 5) is added by: Manager: 1 name: qr
addBranch E 18 1
EMS$ Branch: ID: 5, Name: E, Position: (18, 1) is added by: Manager: 1 name: qr
addLink 1 3
EMS$ rmLink 1 3
EMS$ addLink 1 4
EMS$ addLink 3 4
EMS$ addLink 1 5
EMS$ addLink 5 2
EMS$ addLink 2 5
EMS$ logout
EMS$ customer 0
EMS$ Log in as: [Customer: 0 name: c1]
createOrder item1 1
EMS$ [#1 item1] is created.
searchOrder 1
EMS$ [#1 item1]
ID: 1, Name: A, Position: (1, 1)
searchOrder 1
EMS$ [#1 item1]
ID: 1, Name: A, Position: (1, 1)
searchOrder 1
EMS$ [#1 item1]
ID: 5, Name: E, Position: (18, 1)
Order [item1] is received by [Customer: 1 name: c2]
searchOrder 1
EMS$ Order [#1 item1] is received
logout
EMS$ customer 2
EMS$ Log in as: [Customer: 2 name: c3]
logout
EMS$ customer 1
EMS$ Log in as: [Customer: 1 name: c2]
createOrder item2 0 
EMS$ Exception in thread "main" java.lang.NullPointerException
	at ems.Company.createOrder(Company.java:147)
	at ems.CmdCreateOrder.execute(CmdCreateOrder.java:19)
	at ems.Invoker.StoreAndExecute(Invoker.java:10)
	at ems.Main.main(Main.java:84)

This might be caused because the pathOfBranch in line 147 is empty and NullPointerExceptionis raised.
Comment 1 sherlockqiu 2017-11-26 21:17:40 HKT
Hi ruochen,

The bug has been solved before transverse the entries in the pathOfBranch in Company component. And now the error handler is added for this unreachable error.

Thanks!