Buggy code:
private void markAllAsNotLeader ( final CurrentCoreDescriptorProvider registerOnReconnect ) { } public void close ( ) { } public boolean configFileExists ( String collection , String fileName ) throws InterruptedException , KeeperException { } public ClusterState getClusterState ( ) { } public byte [ ] getConfigFileData ( String zkConfigName , String fileName ) throws InterruptedException , KeeperException { } private String getHostAddress ( String host ) throws IOException { } private String getHostNameFromAddress ( String addr ) { } public String getHostName ( ) { } public String getHostPort ( ) { } public SolrZkClient getZkClient ( ) { } public String getZkServerAddress ( ) { } private void init ( CurrentCoreDescriptorProvider registerOnReconnect ) { } public void publishAndWaitForDownStates ( ) throws InterruptedException , KeeperException { } public static boolean checkChrootPath ( String zkHost , boolean create ) throws InterruptedException , KeeperException { } private static boolean containsChroot ( String zkHost ) { } public boolean isConnected ( ) { } private void createEphemeralLiveNode ( ) throws InterruptedException , KeeperException { } public String getNodeName ( ) { } public boolean pathExists ( String path ) throws InterruptedException , KeeperException { } public String readConfigName ( String collection ) throws InterruptedException , KeeperException { } public String register ( String coreName , final CoreDescriptor desc ) throws Exception { } public String register ( String coreName , final CoreDescriptor desc , boolean recoverReloadedCores , boolean afterExpiration ) throws Exception { final String baseUrl = getBaseUrl ( ) ; final CloudDescriptor cloudDesc = desc . getCloudDescriptor ( ) ; final String collection = cloudDesc . getCollectionName ( ) ; final String coreZkNodeName = desc . getCloudDescriptor ( ) . getCoreNodeName ( ) ; assert coreZkNodeName != null : "we<seq2seq4repair_space>should<seq2seq4repair_space>have<seq2seq4repair_space>a<seq2seq4repair_space>coreNodeName<seq2seq4repair_space>by<seq2seq4repair_space>now" ; String shardId = cloudDesc . getShardId ( ) ; Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( BASE_URL_PROP , baseUrl ) ; props . put ( CORE_NAME_PROP , coreName ) ; props . put ( NODE_NAME_PROP , getNodeName ( ) ) ; if ( ZkController . log . isInfoEnabled ( ) ) { ZkController . log . info ( ( ( ( ( ( ( ( "Register<seq2seq4repair_space>replica<seq2seq4repair_space>-<seq2seq4repair_space>core:" + coreName ) + "<seq2seq4repair_space>address:" ) + baseUrl ) + "<seq2seq4repair_space>collection:" ) + ( cloudDesc . getCollectionName ( ) ) ) + "<seq2seq4repair_space>shard:" ) + shardId ) ) ; } ZkNodeProps leaderProps = new ZkNodeProps ( props ) ; try { joinElection ( desc , afterExpiration ) ; } catch ( InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; throw new org . apache . solr . common . cloud . ZooKeeperException ( ErrorCode . SERVER_ERROR , "" , e ) ; } catch ( KeeperException e ) { throw new org . apache . solr . common . cloud . ZooKeeperException ( ErrorCode . SERVER_ERROR , "" , e ) ; } catch ( IOException e ) { throw new org . apache . solr . common . cloud . ZooKeeperException ( ErrorCode . SERVER_ERROR , "" , e ) ; } String leaderUrl = getLeader ( cloudDesc , ( ( Integer . parseInt ( leaderVoteWait ) ) + 600000 ) ) ; String ourUrl = ZkCoreNodeProps . getCoreUrl ( baseUrl , coreName ) ; ZkController . log . info ( ( ( ( "We<seq2seq4repair_space>are<seq2seq4repair_space>" + ourUrl ) + "<seq2seq4repair_space>and<seq2seq4repair_space>leader<seq2seq4repair_space>is<seq2seq4repair_space>" ) + leaderUrl ) ) ; boolean isLeader = leaderUrl . equals ( ourUrl ) ; SolrCore core = null ; try { core = cc . getCore ( desc . getName ( ) ) ; UpdateLog ulog = core . getUpdateHandler ( ) . getUpdateLog ( ) ; if ( ( ! ( core . isReloaded ( ) ) ) && ( ulog != null ) ) { Slice slice = getClusterState ( ) . getSlice ( collection , shardId ) ; <START_BUG> if ( ( ! ( CONSTRUCTION . equals ( slice . getState ( ) ) ) ) && ( ! isLeader ) ) { <END_BUG> Future < UpdateLog . RecoveryInfo > recoveryFuture = core . getUpdateHandler ( ) . getUpdateLog ( ) . recoverFromLog ( ) ; if ( recoveryFuture != null ) { recoveryFuture . get ( ) ; } else { ZkController . log . info ( ( ( ( "No<seq2seq4repair_space>LogReplay<seq2seq4repair_space>needed<seq2seq4repair_space>for<seq2seq4repair_space>core=" + ( core . getName ( ) ) ) + "<seq2seq4repair_space>baseURL=" ) + baseUrl ) ) ; } } boolean didRecovery = checkRecovery ( coreName , desc , recoverReloadedCores , isLeader , cloudDesc , collection , coreZkNodeName , shardId , leaderProps , core , cc ) ; if ( ! didRecovery ) { publish ( desc , ACTIVE ) ; } } } finally { if ( core != null ) { core . close ( ) ; } } zkStateReader . updateClusterState ( true ) ; return shardId ; } private String getLeader ( final CloudDescriptor cloudDesc , int timeoutms ) { } public ZkCoreNodeProps getLeaderProps ( final String collection , final String slice , int timeoutms ) throws InterruptedException { } public ZkCoreNodeProps getLeaderProps ( final String collection , final String slice , int timeoutms , boolean failImmediatelyOnExpiration ) throws InterruptedException { } private void joinElection ( CoreDescriptor cd , boolean afterExpiration ) throws IOException , InterruptedException , KeeperException { } private boolean checkRecovery ( String coreName , final CoreDescriptor desc , boolean recoverReloadedCores , final boolean isLeader , final CloudDescriptor cloudDesc , final String collection , final String shardZkNodeName , String shardId , ZkNodeProps leaderProps , SolrCore core , CoreContainer cc ) { } public String getBaseUrl ( ) { } public void publish ( final CoreDescriptor cd , final String state ) throws InterruptedException , KeeperException { } public void publish ( final CoreDescriptor cd , final String state , boolean updateLastState ) throws InterruptedException , KeeperException { } private boolean needsToBeAssignedShardId ( final CoreDescriptor desc , final ClusterState state , final String coreNodeName ) { }

Fix:
if ( ( ! ( CONSTRUCTION . equals ( slice . getState ( ) ) ) ) || ( ! isLeader ) ) {