Buggy code:
public class Server extends RunnableUnicastRemoteObject implements RemoteServer { private static final long serialVersionUID = - 6886770266188997347L ; private ArrayList < RemoteClient > clients = new ArrayList < RemoteClient > ( ) ; private ArrayList < RemoteClient > free = new ArrayList < RemoteClient > ( ) ; private Lock gameStarting = new ReentrantLock ( ) ; private ArrayList < Server . RunningMatch > runningMatches = new ArrayList < > ( ) ; private List < Game > games ; private final int gameRescheduleTimer = 2000 ; public ServerGUI gui ; ImageWindow imageWindow ; public final ServerEnvironment env ; private Registry registry = null ; Thread thread = null ; public Server ( ServerEnvironment env ) throws RemoteException { } @ SuppressWarnings ( "unchecked" ) @ Override public void onRun ( ) throws IOException , InterruptedException , MalformedURLException , RemoteException { thread = Thread . currentThread ( ) ; String gamesFileText = FileUtils . readFileToString ( env . gameList ) ; games = new Yaml ( new common . yaml . GameConstructor ( env . botDir ) ) . loadAs ( gamesFileText , List . class ) ; tryWriteResults ( ) ; gui = new ServerGUI ( this ) ; registry = LocateRegistry . createRegistry ( env . port ) ; registry . rebind ( env . serverUrlPath , this ) ; log ( "server<seq2seq4repair_space>listening<seq2seq4repair_space>on<seq2seq4repair_space>'%s'" , Helper . getEndpointAddress ( this ) ) ; int finishedRound = - 1 ; int printedWaitingForRoundToFinish = - 1 ; Game prevGame = null ; Game nextGame = null ; while ( ! ( games . stream ( ) . allMatch ( ( g ) -> g . results != null ) ) ) { nextGame = Server . getNextUnstartedGame ( games , runningMatches ) ; <START_BUG> if ( ( prevGame != null ) && ( ( nextGame == null ) || ( ( nextGame . round ) > ( prevGame . round ) ) ) ) { <END_BUG> if ( ( runningMatches . isEmpty ( ) ) && ( finishedRound < ( prevGame . round ) ) ) { log ( "Round<seq2seq4repair_space>%d<seq2seq4repair_space>finished,<seq2seq4repair_space>moving<seq2seq4repair_space>write<seq2seq4repair_space>directory<seq2seq4repair_space>to<seq2seq4repair_space>read<seq2seq4repair_space>directory" , prevGame . round ) ; for ( Bot bot : Server . getAllBots ( games ) ) FileUtils . copyDirectory ( bot . getWriteDir ( env . botDir ) , bot . getReadDir ( env . botDir ) ) ; finishedRound = prevGame . round ; continue ; } else if ( printedWaitingForRoundToFinish < ( prevGame . round ) ) { log ( "Waiting<seq2seq4repair_space>for<seq2seq4repair_space>ongoing<seq2seq4repair_space>games<seq2seq4repair_space>in<seq2seq4repair_space>round<seq2seq4repair_space>%d<seq2seq4repair_space>to<seq2seq4repair_space>finish" , prevGame . round ) ; printedWaitingForRoundToFinish = prevGame . round ; } } else if ( nextGame != null ) { List < RemoteClient > players = getFree ( nextGame . bots . length ) ; if ( ( players != null ) && ( gameStarting . tryLock ( ) ) ) { Server . RunningMatch runningGame = new Server . RunningMatch ( nextGame , players ) ; runningMatches . add ( runningGame ) ; new Thread ( runningGame ) . start ( ) ; log ( ( nextGame + "<seq2seq4repair_space>starting" ) ) ; prevGame = nextGame ; } } Thread . sleep ( gameRescheduleTimer ) ; } log ( "Done" ) ; if ( ! ( env . exitWhenDone ) ) Thread . sleep ( Long . MAX_VALUE ) ; } @ Override public void onExit ( ) throws AccessException , NotBoundException , RemoteException { } private List < RemoteClient > getFree ( int playerCount ) { } public void tryWriteResults ( ) { } public void getAndDisplayScreenshotFromClient ( RemoteClient client ) { } public synchronized void sendCommandToAllClients ( String command ) { } void killClients ( ) { } public synchronized void log ( String format , Object ... args ) { } @ Override public void connect ( RemoteClient client ) { } @ Override public void disconnect ( RemoteClient client ) { } @ Override public boolean isAlive ( ) { } class RunningMatch implements Runnable { private final Game game ; private final List < RemoteClient > players ; private long startTime ; RunningMatch ( Game game , List < RemoteClient > players ) { } @ Override public void run ( ) { } } private static Game getNextUnstartedGame ( Collection < Game > games , Collection < Server . RunningMatch > runningMatches ) { } private static List < Game > getRunningGames ( Collection < Server . RunningMatch > runningMatches ) { } private static Set < Bot > getAllBots ( List < Game > games ) { } }

Fix:
if ( ( ( prevGame != null ) && ( ( nextGame == null ) || ( ( nextGame . round ) > ( prevGame . round ) ) ) ) && ( ( prevGame . round ) != finishedRound ) ) {