Buggy code:
public class Spider implements Runnable , Task { protected Downloader downloader ; protected List < Pipeline > pipelines = new ArrayList < Pipeline > ( ) ; protected PageProcessor pageProcessor ; protected List < Request > startRequests ; protected Site site ; protected String uuid ; protected Scheduler scheduler = new QueueScheduler ( ) ; protected Logger logger = LoggerFactory . getLogger ( getClass ( ) ) ; protected CountableThreadPool threadPool ; protected ExecutorService executorService ; protected int threadNum = 1 ; protected AtomicInteger stat = new AtomicInteger ( Spider . STAT_INIT ) ; protected boolean exitWhenComplete = true ; protected static final int STAT_INIT = 0 ; protected static final int STAT_RUNNING = 1 ; protected static final int STAT_STOPPED = 2 ; protected boolean spawnUrl = true ; protected boolean destroyWhenExit = true ; private ReentrantLock newUrlLock = new ReentrantLock ( ) ; private Condition newUrlCondition = newUrlLock . newCondition ( ) ; private List < SpiderListener > spiderListeners ; private final AtomicLong pageCount = new AtomicLong ( 0 ) ; private Date startTime ; private int emptySleepTime = 30000 ; private boolean recoverQueue = false ; public static Spider create ( PageProcessor pageProcessor ) { } public Spider ( PageProcessor pageProcessor ) { } public Spider startUrls ( List < String > startUrls ) { } public Spider startRequest ( List < Request > startRequests ) { } public Spider setUUID ( String uuid ) { } public Spider scheduler ( Scheduler scheduler ) { } public Spider setScheduler ( Scheduler scheduler ) { } public Spider pipeline ( Pipeline pipeline ) { } public Spider addPipeline ( Pipeline pipeline ) { } public Spider setPipelines ( List < Pipeline > pipelines ) { } public Spider clearPipeline ( ) { } public Spider downloader ( Downloader downloader ) { } public Spider setDownloader ( Downloader downloader ) { } protected void initComponent ( ) { } @ Override public void run ( ) { checkRunningStat ( ) ; initComponent ( ) ; logger . info ( ( ( "Spider<seq2seq4repair_space>" + ( getUUID ( ) ) ) + "<seq2seq4repair_space>started!" ) ) ; preRun ( ) ; while ( ( ! ( Thread . currentThread ( ) . isInterrupted ( ) ) ) && ( ( stat . get ( ) ) == ( Spider . STAT_RUNNING ) ) ) { Request request = scheduler . poll ( this ) ; if ( request == null ) { if ( ( ( threadPool . getThreadAlive ( ) ) == 0 ) && ( exitWhenComplete ) ) { List < Request > leftRequests = scheduler . checkIfCompleteParse ( this ) ; <START_BUG> if ( ( leftRequests != null ) || ( ( leftRequests . size ( ) ) > 0 ) ) { <END_BUG> logger . info ( "some<seq2seq4repair_space>urls<seq2seq4repair_space>are<seq2seq4repair_space>not<seq2seq4repair_space>parsed:" ) ; for ( Request r : leftRequests ) { logger . info ( r . getUrl ( ) ) ; } logger . info ( "restart<seq2seq4repair_space>un-parsed<seq2seq4repair_space>urls" ) ; for ( Request r : leftRequests ) { scheduler . push ( r , this ) ; } continue ; } break ; } waitNewUrl ( ) ; } else { final Request requestFinal = request ; threadPool . execute ( new Runnable ( ) { @ Override public void run ( ) { try { processRequest ( requestFinal ) ; onSuccess ( requestFinal ) ; } catch ( Exception e ) { onError ( requestFinal ) ; logger . error ( ( ( "process<seq2seq4repair_space>request<seq2seq4repair_space>" + requestFinal ) + "<seq2seq4repair_space>error" ) , e ) ; } finally { if ( ( ( site . getHttpProxyPool ( ) ) != null ) && ( site . getHttpProxyPool ( ) . isEnable ( ) ) ) { site . returnHttpProxyToPool ( requestFinal . getProxy ( ) , requestFinal . getStatusCode ( ) ) ; } pageCount . incrementAndGet ( ) ; signalNewUrl ( ) ; } } } ) ; } } postRun ( ) ; stat . set ( Spider . STAT_STOPPED ) ; if ( destroyWhenExit ) { close ( ) ; } } protected void preRun ( ) { } protected void postRun ( ) { } protected void onError ( Request request ) { } protected void onSuccess ( Request request ) { } private void checkRunningStat ( ) { } public void close ( ) { } private void destroyEach ( Object object ) { } public void test ( String ... urls ) { } protected void processRequest ( Request request ) { } protected void sleep ( int time ) { } protected void extractAndAddRequests ( Page page , boolean spawnUrl ) { } private void addRequest ( Request request ) { } protected void checkIfRunning ( ) { } public void runAsync ( ) { } public Spider addUrl ( String ... urls ) { } public Spider addUrlForRefresh ( String ... urls ) { } public Spider addUrlPost ( String ... urls ) { } public < T > List < T > getAll ( Collection < String > urls ) { } protected CollectorPipeline getCollectorPipeline ( ) { } public < T > T get ( String url ) { } public Spider addRequest ( Request ... requests ) { } private void waitNewUrl ( ) { } private void signalNewUrl ( ) { } public void start ( ) { } public void stop ( ) { } public Spider thread ( int threadNum ) { } public Spider thread ( ExecutorService executorService , int threadNum ) { } public boolean isExitWhenComplete ( ) { } public Spider setExitWhenComplete ( boolean exitWhenComplete ) { } public boolean isSpawnUrl ( ) { } public long getPageCount ( ) { } public Spider . Status getStatus ( ) { } public enum Status { Init ( 0 ) , Running ( 1 ) , Stopped ( 2 ) ; private Status ( int value ) { } private int value ;

Fix:
if ( ( leftRequests != null ) && ( ( leftRequests . size ( ) ) > 0 ) ) {