Buggy code:
i < ( result . length ) ; ++ i ) { activeAgent [ i ] = result [ i ] . getName ( ) ; } System . out . println ( "------------------------------------\n" ) ; ACLMessage cfp = new ACLMessage ( ACLMessage . CFP ) ; for ( int i = 0 ; i < ( result . length ) ; ++ i ) { cfp . addReceiver ( result [ i ] . getName ( ) ) ; } System . out . println ( ( ( myAgent . getLocalName ( ) ) + ":<seq2seq4repair_space>Requesting<seq2seq4repair_space>pieces" ) ) ; cfp . setContentObject ( mappy ) ; cfp . setConversationId ( "select-shelf" ) ; myAgent . send ( cfp ) ; MessageTemplate selectShelfTemplate = MessageTemplate . MatchConversationId ( "select-shelf" ) ; ArrayList < AID > viableAgents = new ArrayList < AID > ( ) ; while ( ( repliesCnt ) < ( activeAgent . length ) ) { ACLMessage reply = myAgent . receive ( selectShelfTemplate ) ; if ( reply != null ) { if ( ( reply . getPerformative ( ) ) == ( ACLMessage . PROPOSE ) ) { viableAgents . add ( reply . getSender ( ) ) ; double [ ] shelfPosition = ( ( double [ ] ) ( reply . getContentObject ( ) ) ) ; Pose shelfPose = new Pose ( ) ; shelfPose = shelfPose . arrayToPose ( shelfPosition ) ; double distance = shelfPose . distance ( position ) ; if ( distance <= ( currentMinDistance ) ) { currentMinDistance = distance ; closestShelf = reply . getSender ( ) ; currentBestPose = shelfPose ; } } ( repliesCnt ) ++ ; } else { block ( ) ; } } System . out . println ( ( ( ( myAgent . getLocalName ( ) ) + ":<seq2seq4repair_space>Selected<seq2seq4repair_space>Closest<seq2seq4repair_space>Shelf:<seq2seq4repair_space>" ) + ( closestShelf ) ) ) ; ACLMessage informMsg = new ACLMessage ( ACLMessage . INFORM ) ; for ( int i = 0 ; i < ( viableAgents . size ( ) ) ; i ++ ) { if ( ( viableAgents . get ( i ) ) != ( closestShelf ) ) { informMsg . addReceiver ( viableAgents . get ( i ) ) ; } } informMsg . setContent ( "REREGISTER" ) ; myAgent . send ( informMsg ) ; ACLMessage notify = new ACLMessage ( ACLMessage . INFORM ) ; notify . setOntology ( "Check<seq2seq4repair_space>Part<seq2seq4repair_space>List" ) ; notify . addReceiver ( msg . getSender ( ) ) ; send ( notify ) ; addBehaviour ( new PickerAgent . GetRobotAgents ( myAgent , currentBestPose , closestShelf , orderAgent ) ) ; } catch ( FIPAException e1 ) { e1 . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } catch ( UnreadableException e ) { e . printStackTrace ( ) ; } busy = true ; try { Thread . sleep ( 10000 ) ; } catch ( Exception e ) { } } else { block ( ) ; } } } private class GetNewOrder extends OneShotBehaviour { public void action ( ) { DFAgentDescription template = new DFAgentDescription ( ) ; ServiceDescription sd = new ServiceDescription ( ) ; sd . setType ( "order" ) ; template . addServices ( sd ) ; System . out . println ( "------------------------------------" ) ; try { DFAgentDescription [ ] orders = DFService . search ( myAgent , template ) ; System . out . println ( ( ( myAgent . getLocalName ( ) ) + "<seq2seq4repair_space>[searching<seq2seq4repair_space>orders]." ) ) ; System . out . println ( "Found<seq2seq4repair_space>the<seq2seq4repair_space>following<seq2seq4repair_space>orders:" ) ; activeAgent = new AID [ orders . length ] ; if ( ( orders . length ) == 0 ) { System . out . println ( "<seq2seq4repair_space>><seq2seq4repair_space>No<seq2seq4repair_space>available<seq2seq4repair_space>orders." ) ; } else { for ( int i = 0 ; i < ( orders . length ) ; ++ i ) { activeAgent [ i ] = orders [ i ] . getName ( ) ; System . out . println ( ( "<seq2seq4repair_space>><seq2seq4repair_space>" + ( activeAgent [ i ] . getName ( ) ) ) ) ; } System . out . println ( "------------------------------------\n" ) ; ACLMessage assign = new ACLMessage ( ACLMessage . REQUEST ) ; assign . addReceiver ( orders [ ( ( orders . length ) - 1 ) ] . getName ( ) ) ; assign . setOntology ( "assignment" ) ; myAgent . send ( assign ) ; System . out . println ( ( ( ( ( getLocalName ( ) ) + ":<seq2seq4repair_space>Requested<seq2seq4repair_space>" ) + ( orders [ ( ( orders . length ) - 1 ) ] . getName ( ) . getLocalName ( ) ) ) + "." ) ) ; } } catch ( FIPAException fe ) { System . err . println ( ( ( myAgent . getLocalName ( ) ) + ":<seq2seq4repair_space>Error<seq2seq4repair_space>sending<seq2seq4repair_space>the<seq2seq4repair_space>message." ) ) ; } } } private class OrderUpdate extends CyclicBehaviour { public void action ( ) { MessageTemplate orderMT = MessageTemplate . and ( MessageTemplate . MatchPerformative ( CONFIRM ) , MessageTemplate . MatchOntology ( "Final<seq2seq4repair_space>Shelf" ) ) ; MessageTemplate shelfMT = MessageTemplate . and ( MessageTemplate . MatchPerformative ( INFORM ) , MessageTemplate . MatchOntology ( "Shelf<seq2seq4repair_space>on<seq2seq4repair_space>place" ) ) ; ACLMessage orderMsg = myAgent . receive ( orderMT ) ; ACLMessage shelfMsg = myAgent . receive ( shelfMT ) ; ACLMessage reply = new ACLMessage ( ACLMessage . CONFIRM ) ; reply . setOntology ( "Completed<seq2seq4repair_space>Order" ) ; <START_BUG> if ( ( orderMsg != null ) && ( shelfMsg != null ) ) { <END_BUG> System . out . println ( ( ( myAgent . getLocalName ( ) ) + ":<seq2seq4repair_space>Requesting<seq2seq4repair_space>new<seq2seq4repair_space>order." ) ) ; reply . addReceiver ( orderMsg . getSender ( ) ) ; send ( reply ) ; addBehaviour ( new PickerAgent . GetNewOrder ( ) ) ; } else { block ( ) ; } } } }

Fix:
if ( orderMsg != null ) {