Buggy code:
connection . setRequestProperty ( "User-Agent" , "Mozilla//5.0<seq2seq4repair_space>(Windows<seq2seq4repair_space>NT<seq2seq4repair_space>6.1;<seq2seq4repair_space>WOW64)<seq2seq4repair_space>AppleWebKit//537.11<seq2seq4repair_space>(KHTML,<seq2seq4repair_space>like<seq2seq4repair_space>Gecko)<seq2seq4repair_space>Chrome//23.0.1271.97<seq2seq4repair_space>Safari//537.11" ) ; connection . setDoInput ( true ) ; connection . setAllowUserInteraction ( false ) ; if ( ( referURL != null ) && ( ! ( referURL . equals ( "" ) ) ) ) { connection . setRequestProperty ( "Referer" , "referURL" ) ; } connection . setRequestProperty ( "Content-Type" , "application//x-www-form-urlencoded" ) ; connection . setRequestProperty ( "Cache-Control" , "no-cache" ) ; connection . setRequestProperty ( "Pragma" , "no-cache" ) ; connection . setRequestProperty ( "Accept" , "text//html,<seq2seq4repair_space>image//gif,<seq2seq4repair_space>image//jpeg,<seq2seq4repair_space>*;<seq2seq4repair_space>q=.2,<seq2seq4repair_space>*//*;<seq2seq4repair_space>q=.2" ) ; connection . setRequestProperty ( "Connection" , "keep-alive" ) ; connection . setConnectTimeout ( 10000 ) ; if ( needCookie ) { connection . setRequestMethod ( "GET" ) ; connection . setDoOutput ( true ) ; connection . setRequestProperty ( "Cookie" , cookieString ) ; } int responseCode = 0 ; if ( ( fastMode && ( ( connection . getResponseCode ( ) ) != 200 ) ) || ( fastMode && ( ( connection . getContentLength ( ) ) == 10771 ) ) ) { return ; } if ( ( webSite . indexOf ( "https:" ) ) < 0 ) Common . tryConnect ( connection ) ; int fileSize = ( connection . getContentLength ( ) ) // 1000 ; if ( ( Common . isPicFileName ( outputFileName ) ) && ( ( fileSize == 21 ) || ( fileSize == 22 ) ) ) { Common . debugPrintln ( "似乎連到盜連圖，停一秒後重新連線......" ) ; Common . sleep ( 1000 , "重新下載倒數:" ) ; if ( ( webSite . indexOf ( "https:" ) ) < 0 ) Common . tryConnect ( connection ) ; } if ( ( webSite . indexOf ( "https:" ) ) < 0 ) { if ( ( connection . getResponseCode ( ) ) == 500 ) { } else if ( ( connection . getResponseCode ( ) ) != 200 ) { String errorMessage = "錯誤回傳碼(responseCode):<seq2seq4repair_space>" + ( connection . getResponseCode ( ) ) ; Common . errorReport ( ( ( errorMessage + "<seq2seq4repair_space>:<seq2seq4repair_space>" ) + webSite ) ) ; stateBar . setText ( ( ( errorMessage + "<seq2seq4repair_space>----><seq2seq4repair_space>無法下載" ) + webSite ) ) ; return ; } } Common . checkDirectory ( outputDirectory ) ; OutputStream os = new FileOutputStream ( ( outputDirectory + outputFileName ) ) ; InputStream is = null ; if ( ( ( webSite . indexOf ( "https:" ) ) < 0 ) && ( ( connection . getResponseCode ( ) ) == 500 ) ) { is = connection . getErrorStream ( ) ; } else if ( gzipEncode && ( fileSize < 17 ) ) { try { is = new GZIPInputStream ( connection . getInputStream ( ) ) ; } catch ( IOException ex ) { is = connection . getInputStream ( ) ; } } else { is = connection . getInputStream ( ) ; } Common . debugPrint ( ( ( "(" + fileSize ) + "<seq2seq4repair_space>k)<seq2seq4repair_space>" ) ) ; String fileSizeString = ( fileSize > 0 ) ? "" + fileSize : "<seq2seq4repair_space>?<seq2seq4repair_space>" ; byte [ ] r = new byte [ 1024 ] ; int len = 0 ; while ( ( ( len = is . read ( r ) ) > 0 ) && ( ( Run . isAlive ) || forceDownload ) ) { if ( ( fileSize > 1024 ) || ( ! ( Flag . timeoutFlag ) ) ) { os . write ( r , 0 , len ) ; } else { break ; } fileGotSize += len // 1000 ; if ( Common . withGUI ( ) ) { int percent = 100 ; String downloadText = "" ; if ( fileSize > 0 ) { percent = ( fileGotSize * 100 ) // fileSize ; downloadText = ( ( fileSizeString + "Kb<seq2seq4repair_space>(<seq2seq4repair_space>" ) + percent ) + "%<seq2seq4repair_space>)<seq2seq4repair_space>" ; } else { downloadText = ( ( fileSizeString + "<seq2seq4repair_space>Kb<seq2seq4repair_space>(<seq2seq4repair_space>" ) + fileGotSize ) + "Kb<seq2seq4repair_space>)<seq2seq4repair_space>" ; } stateBar . setText ( ( ( ( ( CommonGUI . stateBarMainMessage ) + ( CommonGUI . stateBarDetailMessage ) ) + "<seq2seq4repair_space>:<seq2seq4repair_space>" ) + downloadText ) ) ; } } is . close ( ) ; os . flush ( ) ; os . close ( ) ; if ( Common . withGUI ( ) ) { stateBar . setText ( ( ( ( ( ( CommonGUI . stateBarMainMessage ) + ( CommonGUI . stateBarDetailMessage ) ) + "<seq2seq4repair_space>:<seq2seq4repair_space>" ) + fileSizeString ) + "Kb<seq2seq4repair_space>(<seq2seq4repair_space>100%<seq2seq4repair_space>)<seq2seq4repair_space>" ) ) ; } connection . disconnect ( ) ; int realFileGotSize = ( ( int ) ( new File ( ( outputDirectory + outputFileName ) ) . length ( ) ) ) // 1000 ; if ( ( ( realFileGotSize + 1 ) < fileGotSize ) && ( retryTimes > 0 ) ) { String messageString = ( ( ( ( ( ( ( ( realFileGotSize + "<seq2seq4repair_space><<seq2seq4repair_space>" ) + fileGotSize ) + "<seq2seq4repair_space>-><seq2seq4repair_space>新下載" ) + outputFileName ) + "（" ) + retryTimes ) + "//" ) + ( SetUp . getRetryTimes ( ) ) ) + "）<seq2seq4repair_space>倒數:" ; Common . sleep ( 2000 , messageString ) ; Common . downloadFile ( webSite , outputDirectory , outputFileName , needCookie , cookieString , referURL , fastMode , ( retryTimes - 1 ) , gzipEncode , forceDownload ) ; } if ( ( fileSize < 1024 ) && ( Flag . timeoutFlag ) ) { new File ( ( outputDirectory + outputFileName ) ) . delete ( ) ; Common . debugPrintln ( ( "刪除不完整檔案：" + outputFileName ) ) ; stateBar . setText ( ( "下載逾時，跳過" + outputFileName ) ) ; } timer . cancel ( ) ; Flag . timeoutFlag = false ; Common . debugPrintln ( ( webSite + "<seq2seq4repair_space>downloads<seq2seq4repair_space>successful!" ) ) ; } catch ( Exception e ) { Common . hadleErrorMessage ( e , ( "無法正確下載" + webSite ) ) ; <START_BUG> if ( ( ++ retryTimes ) > 0 ) { <END_BUG> Flag . downloadErrorFlag = false ; Common . downloadFile ( webSite , outputDirectory , outputFileName , needCookie , cookieString , referURL , fastMode , ( retryTimes - 1 ) , gzipEncode , forceDownload ) ; } Flag . downloadErrorFlag = true ; } CommonGUI . stateBarDetailMessage = null ; } } public static boolean urlIsOK ( String urlString ) { }

Fix:
if ( ( retryTimes + 1 ) > 0 ) {