Buggy code:
public class WiFiDirectBroadcast extends BroadcastReceiver { private static final String TAG = "WiFiDirectBroadcast" ; private WifiP2pManager mManager ; private Channel mChannel ; private ProducerActivity mProducerActivity ; private PhotoSharingApplication app ; String oAddress ; String localIP ; boolean isOwner ; private WifiP2pDevice myself ; private List peers = new ArrayList ( ) ; public WiFiDirectBroadcast ( WifiP2pManager manager , WifiP2pManager . Channel channel , ProducerActivity activity ) { } @ Override public void onReceive ( Context context , Intent intent ) { } private byte [ ] getLocalIPAddress ( ) { } private String getDottedDecimalIP ( byte [ ] ipAddr ) { } private class RequestOwner extends AsyncTask < Void , Void , Void > { private InetAddress groupOwnerAddress ; private ProducerActivityFragment fragment ; private Face mFace ; private String returnData = "No<seq2seq4repair_space>return<seq2seq4repair_space>data" ; @ Override protected Void doInBackground ( Void ... params ) { mManager . requestConnectionInfo ( mChannel , new WifiP2pManager . ConnectionInfoListener ( ) { @ Override public void onConnectionInfoAvailable ( WifiP2pInfo info ) { try { groupOwnerAddress = info . groupOwnerAddress ; fragment = ( ( ProducerActivityFragment ) ( mProducerActivity . getFragmentManager ( ) . findFragmentById ( producer_fragment ) ) ) ; oAddress = groupOwnerAddress . getHostAddress ( ) ; isOwner = info . isGroupOwner ; mFace = new Face ( "localhost" ) ; KeyChain keyChain = ProducerActivityFragment . buildTestKeyChain ( ) ; mFace . setCommandSigningInfo ( keyChain , keyChain . getDefaultCertificateName ( ) ) ; int mPort = 3000 ; if ( ! ( isOwner ) ) { localIP = getDottedDecimalIP ( getLocalIPAddress ( ) ) ; Thread t = new Thread ( new Runnable ( ) { @ Override public void run ( ) { try { int mPort = 3000 ; Socket socket = new Socket ( ) ; socket . setReuseAddress ( true ) ; socket . connect ( new InetSocketAddress ( oAddress , mPort ) , socket . getSoTimeout ( ) ) ; OutputStream os = socket . getOutputStream ( ) ; ObjectOutputStream oos = new ObjectOutputStream ( os ) ; oos . writeObject ( myself . deviceName ) ; oos . close ( ) ; os . close ( ) ; socket . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } } ) ; t . start ( ) ; Log . i ( ProducerActivity . TAG , "NON-owner<seq2seq4repair_space>LOGIC<seq2seq4repair_space>DONE" ) ; } else { Log . i ( ProducerActivity . TAG , "i'm<seq2seq4repair_space>the<seq2seq4repair_space>owner" ) ; localIP = oAddress ; Thread t = new Thread ( new Runnable ( ) { @ Override public void run ( ) { try { int mPort = 3000 ; ServerSocket serverSocket = new ServerSocket ( mPort ) ; serverSocket . setReuseAddress ( true ) ; Socket client = serverSocket . accept ( ) ; ObjectInputStream objectInputStream = new ObjectInputStream ( client . getInputStream ( ) ) ; Object object = objectInputStream . readObject ( ) ; if ( object . getClass ( ) . equals ( String . class ) ) { Log . i ( WiFiDirectBroadcast . TAG , ( "Client<seq2seq4repair_space>IP<seq2seq4repair_space>address:<seq2seq4repair_space>" + ( client . getInetAddress ( ) ) ) ) ; Log . i ( WiFiDirectBroadcast . TAG , ( "Client<seq2seq4repair_space>device<seq2seq4repair_space>name:" + ( ( String ) ( object ) ) ) ) ; app . addDevice ( client . getInetAddress ( ) . toString ( ) , ( ( String ) ( object ) ) ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } } } ) ; t . start ( ) ; Log . i ( ProducerActivity . TAG , "OWNER<seq2seq4repair_space>LOGIC<seq2seq4repair_space>DONE" ) ; } app . setOwnerAddress ( oAddress ) ; Log . i ( ProducerActivity . TAG , ( "Owner<seq2seq4repair_space>Address:<seq2seq4repair_space>" + ( oAddress ) ) ) ; app . setMyAddress ( localIP ) ; Log . i ( ProducerActivity . TAG , ( "My<seq2seq4repair_space>Address:" + ( localIP ) ) ) ; if ( oAddress . equals ( localIP ) ) { <START_BUG> app . addDevice ( localIP , "owner" ) ; <END_BUG> } Log . i ( ProducerActivity . TAG , ( "Register<seq2seq4repair_space>status:<seq2seq4repair_space>" + ( returnData ) ) ) ; fragment . updateGroupOwner ( isOwner , oAddress ) ; fragment . updateMyAddress ( localIP ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; Log . e ( ProducerActivity . TAG , e . toString ( ) ) ; } } } ) ; return null ; } } }

Fix:
app . addDevice ( localIP , myself . deviceName ) ;