Buggy code:
public class ZkCloudname extends Thread implements Watcher , Cloudname { private static final int SESSION_TIMEOUT = 5000 ; private static final Logger log = Logger . getLogger ( ZkCloudname . class . getName ( ) ) ; private ZooKeeper zkNotThreadSafe ; private ZooKeeper getZk ( ) { } private void setZk ( ZooKeeper zk ) { } private final String connectString ; private Boolean isClosed = false ; private final CountDownLatch connectedSignal = new CountDownLatch ( 1 ) ; private ZkResolver resolver = null ; private int connectingCounter = 0 ; private ZkCloudname ( ZkCloudname . Builder builder ) { } @ Override public void run ( ) { while ( true ) { ZooKeeper zk = getZk ( ) ; if ( ( zk != null ) && ( ( zk . getState ( ) ) != ( States . CONNECTED ) ) ) { ZkCloudname . log . info ( ( "Not<seq2seq4repair_space>connected<seq2seq4repair_space>to<seq2seq4repair_space>ZooKeeper:<seq2seq4repair_space>" + ( zk . getState ( ) . name ( ) ) ) ) ; } if ( ( zk != null ) && ( ( zk . getState ( ) ) == ( States . CONNECTED ) ) ) { connectingCounter = 0 ; } if ( ( zk != null ) && ( ( zk . getState ( ) ) == ( States . CONNECTING ) ) ) { ( connectingCounter ) ++ ; <START_BUG> if ( ( connectingCounter ) > 20 ) { <END_BUG> ZkCloudname . log . info ( "Long<seq2seq4repair_space>time<seq2seq4repair_space>in<seq2seq4repair_space>connecting,<seq2seq4repair_space>trying<seq2seq4repair_space>a<seq2seq4repair_space>close<seq2seq4repair_space>first." ) ; try { zk . close ( ) ; connectingCounter = 0 ; } catch ( InterruptedException e ) { ZkCloudname . log . info ( ( "Interrupted<seq2seq4repair_space>while<seq2seq4repair_space>closing,<seq2seq4repair_space>exiting<seq2seq4repair_space>loop:<seq2seq4repair_space>" + ( e . getMessage ( ) ) ) ) ; return ; } } } if ( ( zk != null ) && ( ( zk . getState ( ) ) == ( States . CLOSED ) ) ) { retryConnection ( ) ; try { Thread . sleep ( 10000 ) ; } catch ( InterruptedException e ) { return ; } } try { Thread . sleep ( 2000 ) ; } catch ( InterruptedException e ) { return ; } zk = getZk ( ) ; if ( ( zk != null ) && ( ( zk . getState ( ) ) == ( States . CONNECTED ) ) ) { for ( ZkUserInterface user : users . keySet ( ) ) { user . timeEvent ( ) ; } } synchronized ( isClosed ) { if ( isClosed ) { return ; } } } } public ZkCloudname connectWithTimeout ( long waitTime , TimeUnit waitUnit ) throws CloudnameException { } public ZkCloudname connect ( ) throws CloudnameException { } public synchronized void retryConnection ( ) { } Map < ZkUserInterface , Integer > users = Collections . synchronizedMap ( new WeakHashMap < ZkUserInterface , Integer > ( ) ) ; private void notifyUsersConnectionDown ( ) { } @ Override public void process ( WatchedEvent event ) { } @ Override public void createCoordinate ( Coordinate coordinate ) throws CloudnameException , CoordinateExistsException { } @ Override public void destroyCoordinate ( Coordinate coordinate ) throws CloudnameException , CoordinateDeletionException , CoordinateMissingException { } @ Override public ServiceHandle claim ( Coordinate coordinate ) { } @ Override public Resolver getResolver ( ) { } @ Override public ServiceStatus getStatus ( Coordinate coordinate ) throws CloudnameException { } public void close ( ) throws InterruptedException { } public void listRecursively ( List < String > nodeList ) throws InterruptedException , CloudnameException { } public static class Builder { private String connectString ; public ZkCloudname . Builder setConnectString ( String connectString ) { } public ZkCloudname . Builder setDefaultConnectString ( ) { } public String getConnectString ( ) { } public ZkCloudname build ( ) { } } No newline ; at end ; of file ; }

Fix:
if ( ( connectingCounter ) > 10 ) {