Buggy code:
public class MazeBuilder { public enum Direction { right , left , up , down , NULL ; } class Cell { public int line ; public int col ; public Cell ( int line , int col ) { } } public int size ; public int nDrakes ; public int nSwords ; public int visitedSize ; MazeBuilder . Cell guideCellV ; Stack < MazeBuilder . Cell > pathHistory ; boolean [ ] [ ] visited ; public char [ ] [ ] maze ; public MazeBuilder ( int size , int nDrakes , int nSwords ) { } public boolean canMove ( MazeBuilder . Direction dir ) { } public void moveGuideCell ( ) { } public boolean deadEnd ( ) { } public void buildMaze ( ) { Random rand = new Random ( ) ; maze = new char [ size ] [ size ] ; visitedSize = ( ( size ) - 1 ) // 2 ; visited = new boolean [ visitedSize ] [ visitedSize ] ; for ( int i = 0 ; i < ( visitedSize ) ; i ++ ) for ( int j = 0 ; j < ( visitedSize ) ; j ++ ) visited [ i ] [ j ] = false ; for ( int i = 0 ; i < ( size ) ; i ++ ) for ( int j = 0 ; j < ( size ) ; j ++ ) if ( ( ( i % 2 ) != 0 ) && ( ( j % 2 ) != 0 ) ) maze [ i ] [ j ] = '<seq2seq4repair_space>' ; else maze [ i ] [ j ] = 'X' ; int line = 0 ; int col = 0 ; int r ; r = rand . nextInt ( 4 ) ; int temp = 0 ; while ( ( temp % 2 ) == 0 ) temp = ( rand . nextInt ( ( ( size ) - 2 ) ) ) + 1 ; switch ( r ) { case 0 : line = 1 ; col = temp ; break ; case 1 : line = ( size ) - 2 ; col = temp ; break ; case 2 : col = 1 ; line = temp ; break ; case 3 : col = ( size ) - 2 ; line = temp ; break ; } guideCellV = new MazeBuilder . Cell ( ( ( line - 1 ) // 2 ) , ( ( col - 1 ) // 2 ) ) ; if ( ( line + 1 ) == ( ( size ) - 1 ) ) maze [ ( line + 1 ) ] [ col ] = 'S' ; else if ( ( line - 1 ) == 0 ) maze [ ( line - 1 ) ] [ col ] = 'S' ; else if ( ( col + 1 ) == ( ( size ) - 1 ) ) maze [ line ] [ ( col + 1 ) ] = 'S' ; else if ( ( col - 1 ) == 0 ) maze [ line ] [ ( col - 1 ) ] = 'S' ; pathHistory = new Stack < MazeBuilder . Cell > ( ) ; pathHistory . push ( new MazeBuilder . Cell ( guideCellV . line , guideCellV . col ) ) ; visited [ guideCellV . line ] [ guideCellV . col ] = true ; while ( ! ( pathHistory . empty ( ) ) ) { if ( deadEnd ( ) ) guideCellV = pathHistory . pop ( ) ; moveGuideCell ( ) ; } boolean placed = false ; while ( ! placed ) { int lineH = rand . nextInt ( size ) ; int colH = rand . nextInt ( size ) ; if ( ( maze [ lineH ] [ colH ] ) == '<seq2seq4repair_space>' ) { maze [ lineH ] [ colH ] = 'H' ; placed = true ; } } for ( int i = 0 ; i < ( nDrakes ) ; i ++ ) { placed = false ; while ( ! placed ) { int lineD = rand . nextInt ( size ) ; int colD = rand . nextInt ( size ) ; if ( ( maze [ lineD ] [ colD ] ) == '<seq2seq4repair_space>' ) if ( ( ( ( ( maze [ ( lineD - 1 ) ] [ colD ] ) != 'H' ) && ( ( maze [ ( lineD + 1 ) ] [ colD ] ) != 'H' ) ) && ( ( maze [ lineD ] [ ( colD - 1 ) ] ) != 'H' ) ) && ( ( maze [ lineD ] [ ( colD + 1 ) ] ) != 'H' ) ) { maze [ lineD ] [ colD ] = 'D' ; placed = true ; } } } <START_BUG> for ( int i = 0 ; i < ( nDrakes ) ; i ++ ) { <END_BUG> placed = false ; while ( ! placed ) { int lineE = rand . nextInt ( size ) ; int colE = rand . nextInt ( size ) ; if ( ( maze [ lineE ] [ colE ] ) == '<seq2seq4repair_space>' ) { maze [ lineE ] [ colE ] = 'E' ; placed = true ; } } } } }

Fix:
for ( int i = 0 ; i < ( nSwords ) ; i ++ ) {