Buggy code:
public static Connection syncDeck ( Connection . TaskListener listener , Connection . Payload data ) { } public static Connection syncDeckFromPayload ( Connection . TaskListener listener , Connection . Payload data ) { } public static Connection sendFeedback ( Connection . TaskListener listener , Connection . Payload data ) { } public static Connection downloadMissingMedia ( Connection . TaskListener listener , Connection . Payload data ) { } @ Override protected Connection . Payload doInBackground ( Connection . Payload ... params ) { } private Connection . Payload doOneInBackground ( Connection . Payload data ) { } public static void cancelGetSharedDecks ( ) { } private Connection . Payload doInBackgroundLogin ( Connection . Payload data ) { } private Connection . Payload doInBackgroundGetSharedDecks ( Connection . Payload data ) { } private Connection . Payload doInBackgroundGetPersonalDecks ( Connection . Payload data ) { } private Connection . Payload doInBackgroundSyncAllDecks ( Connection . Payload data ) { } private Connection . Payload doInBackgroundSyncDeck ( Connection . Payload data ) { } private Connection . Payload doInBackgroundSyncDeckFromPayload ( Connection . Payload data ) { } private Connection . Payload doInBackgroundSendFeedback ( Connection . Payload data ) { } private Connection . Payload doInBackgroundDownloadMissingMedia ( Connection . Payload data ) { Log . i ( TAG , "DownloadMissingMedia" ) ; HashMap < String , String > missingPaths = new HashMap < String , String > ( ) ; HashMap < String , String > missingSums = new HashMap < String , String > ( ) ; Deck deck = ( ( Deck ) ( data . data [ 0 ] ) ) ; data . result = deck ; String syncName = deck . getDeckName ( ) ; data . success = false ; data . data = new Object [ ] { 0 , 0 , 0 } ; if ( ! ( deck . hasKey ( "mediaURL" ) ) ) { data . success = true ; return data ; } String urlbase = deck . getVar ( "mediaURL" ) ; if ( urlbase . equals ( "" ) ) { data . success = true ; return data ; } String mdir = deck . mediaDir ( true ) ; int totalMissing = 0 ; int missing = 0 ; int grabbed = 0 ; Cursor cursor = null ; try { cursor = deck . getDB ( ) . getDatabase ( ) . rawQuery ( "SELECT<seq2seq4repair_space>filename,<seq2seq4repair_space>originalPath<seq2seq4repair_space>FROM<seq2seq4repair_space>media" , null ) ; String path = null ; String f = null ; while ( cursor . moveToNext ( ) ) { f = cursor . getString ( 0 ) ; path = ( mdir + "//" ) + f ; File file = new File ( path ) ; if ( ! ( file . exists ( ) ) ) { missingPaths . put ( f , path ) ; missingSums . put ( f , cursor . getString ( 1 ) ) ; Log . i ( TAG , ( "Missing<seq2seq4repair_space>file:<seq2seq4repair_space>" + f ) ) ; } } } finally { if ( cursor != null ) { cursor . close ( ) ; } } totalMissing = missingPaths . size ( ) ; data . data [ 0 ] = new Integer ( totalMissing ) ; if ( totalMissing == 0 ) { data . success = true ; return data ; } publishProgress ( Boolean . FALSE , new Integer ( totalMissing ) , new Integer ( 0 ) , syncName ) ; URL url = null ; HttpURLConnection connection = null ; String path = null ; String sum = null ; int readbytes = 0 ; byte [ ] buf = new byte [ 4096 ] ; for ( String file : missingPaths . keySet ( ) ) { try { <START_BUG> Uri uri = Uri . parse ( ( urlbase + ( Uri . encode ( file ) ) ) ) ; <END_BUG> url = new URI ( uri . toString ( ) ) . toURL ( ) ; connection = ( ( HttpURLConnection ) ( url . openConnection ( ) ) ) ; connection . connect ( ) ; if ( ( connection . getResponseCode ( ) ) == 200 ) { path = missingPaths . get ( file ) ; InputStream is = connection . getInputStream ( ) ; BufferedInputStream bis = new BufferedInputStream ( is , 4096 ) ; FileOutputStream fos = new FileOutputStream ( path ) ; while ( ( readbytes = bis . read ( buf , 0 , 4096 ) ) != ( - 1 ) ) { fos . write ( buf , 0 , readbytes ) ; Log . i ( TAG , ( ( ( "Downloaded<seq2seq4repair_space>" + readbytes ) + "<seq2seq4repair_space>file:<seq2seq4repair_space>" ) + path ) ) ; } fos . close ( ) ; sum = missingSums . get ( file ) ; if ( ( sum . equals ( "" ) ) || ( sum . equals ( Utils . fileChecksum ( path ) ) ) ) { grabbed ++ ; } else { Log . i ( TAG , ( ( "Downloaded<seq2seq4repair_space>media<seq2seq4repair_space>file<seq2seq4repair_space>" + path ) + "<seq2seq4repair_space>failed<seq2seq4repair_space>checksum." ) ) ; File f = new File ( path ) ; f . delete ( ) ; missing ++ ; } } else { Log . e ( TAG , ( ( ( ( "Connection<seq2seq4repair_space>error<seq2seq4repair_space>(" + ( connection . getResponseCode ( ) ) ) + ")<seq2seq4repair_space>while<seq2seq4repair_space>retrieving<seq2seq4repair_space>media<seq2seq4repair_space>file<seq2seq4repair_space>" ) + urlbase ) + file ) ) ; Log . e ( TAG , ( "Connection<seq2seq4repair_space>message:<seq2seq4repair_space>" + ( connection . getResponseMessage ( ) ) ) ) ; if ( missingSums . get ( file ) . equals ( "" ) ) { missing ++ ; } else { data . success = false ; data . data = new Object [ ] { file } ; return data ; } } connection . disconnect ( ) ;

Fix:
Uri uri = Uri . parse ( ( ( Uri . encode ( urlbase , "://@%" ) ) + ( Uri . encode ( file ) ) ) ) ;