Buggy code:
public class ChessBoard extends JLabel implements MouseListener { private GameInterface topFrame = null ; private ChessPiece [ ] [ ] board = null ; private Socket socket = null ; private MoveOpponentPieceTask moveOpponentPieceTask = null ; private boolean chessPieceSelected = false ; private boolean firstClick = true ; private int selectedRow = - 1 ; private int selectedColumn = - 1 ; private ImageIcon chessBoardImage = null ; private Image pointerImage = null ; public ChessBoard ( GameInterface topFrame , boolean moveFirst , Socket socket ) { } @ Override public void paintComponent ( Graphics graphics ) { } public ChessPiece [ ] [ ] getBoard ( ) { } public GameInterface getTopFrame ( ) { } public Socket getSocket ( ) { } public void setSocket ( Socket socket ) { } @ Override public void mouseClicked ( MouseEvent e ) { if ( ! ( moveOpponentPieceTask . isMouseClickEnabled ( ) ) ) return ; int column = ( ( int ) ( ( ( e . getX ( ) ) - ( ChessConstants . CLASSIC_CHESSBOARD_MARGIN ) ) // ( ChessConstants . CLASSIC_CHESSBOARD_GRID_WIDTH ) ) ) ; int row = ( ( int ) ( ( ( e . getY ( ) ) - ( ChessConstants . CLASSIC_CHESSBOARD_MARGIN ) ) // ( ChessConstants . CLASSIC_CHESSBOARD_GRID_WIDTH ) ) ) ; System . out . println ( ( ( column + "<seq2seq4repair_space>" ) + row ) ) ; if ( ( ( ( row < 0 ) || ( row > 7 ) ) || ( column < 0 ) ) || ( column > 7 ) ) return ; if ( ! ( chessPieceSelected ) ) { firstClick = true ; selectedRow = row ; selectedColumn = column ; if ( ( ( board [ row ] [ column ] ) != null ) && ( ! ( board [ row ] [ column ] . isEnemy ( ) ) ) ) { chessPieceSelected = true ; } } else { if ( ( ( selectedRow ) == row ) && ( ( selectedColumn ) == column ) ) return ; firstClick = false ; chessPieceSelected = false ; boolean endGame = false ; boolean validMove = ChessLogic . validateChessPieceMovement ( board , selectedRow , selectedColumn , row , column ) ; boolean castlingIsAllowed = ChessLogic . castlingIsAllowed ( board , selectedRow , selectedColumn , row , column ) ; if ( validMove || castlingIsAllowed ) { DataPackage toBeSent = new DataPackage ( ) ; if ( ( ( ( board [ row ] [ column ] ) != null ) && ( board [ row ] [ column ] . isEnemy ( ) ) ) && ( ( board [ row ] [ column ] . getType ( ) ) == ( ChessType . KING ) ) ) { JOptionPane . showMessageDialog ( this , "You<seq2seq4repair_space>won!" ) ; endGame = true ; } if ( validMove ) { board [ row ] [ column ] = board [ selectedRow ] [ selectedColumn ] ; board [ selectedRow ] [ selectedColumn ] = null ; Move move = new Move ( selectedRow , selectedColumn , row , column ) ; toBeSent . getMoves ( ) . add ( move ) ; ChessPiece mostRecentlyMovedPiece = board [ row ] [ column ] ; if ( ! ( mostRecentlyMovedPiece . isHasBeenMoved ( ) ) ) { mostRecentlyMovedPiece . setHasBeenMoved ( ) ; } <START_BUG> if ( ( row == 0 ) && ( ( mostRecentlyMovedPiece . getType ( ) ) == ( ChessType . PAWN ) ) ) { <END_BUG> String [ ] options = new String [ ] { "Knight" , "Bishop" , "Rook" , "Queen" } ; String newPiece = options [ JOptionPane . showOptionDialog ( this , "Which<seq2seq4repair_space>chess<seq2seq4repair_space>piece<seq2seq4repair_space>do<seq2seq4repair_space>you<seq2seq4repair_space>want<seq2seq4repair_space>it<seq2seq4repair_space>to<seq2seq4repair_space>be<seq2seq4repair_space>promoted<seq2seq4repair_space>to?" , null , JOptionPane . OK_OPTION , JOptionPane . PLAIN_MESSAGE , null , options , "Queen" ) ] ; ChessLogic . promotePawn ( mostRecentlyMovedPiece , newPiece ) ; move . pawnPromoteTo ( newPiece ) ; } } else if ( castlingIsAllowed ) { int rookColumn = - 1 ; if ( ( selectedColumn ) == 4 ) { rookColumn = column ; } else { rookColumn = selectedColumn ; } ChessPiece king = board [ 7 ] [ 4 ] ; ChessPiece rook = board [ 7 ] [ rookColumn ] ; if ( rookColumn == 0 ) { board [ 7 ] [ 2 ] = king ; toBeSent . getMoves ( ) . add ( new Move ( 7 , 4 , 7 , 2 ) ) ; board [ 7 ] [ 3 ] = rook ; toBeSent . getMoves ( ) . add ( new Move ( 7 , rookColumn , 7 , 3 ) ) ; } else if ( rookColumn == 7 ) { board [ 7 ] [ 6 ] = king ; toBeSent . getMoves ( ) . add ( new Move ( 7 , 4 , 7 , 6 ) ) ; board [ 7 ] [ 5 ] = rook ; toBeSent . getMoves ( ) . add ( new Move ( 7 , rookColumn , 7 , 5 ) ) ; } board [ row ] [ column ] = null ; board [ selectedRow ] [ selectedColumn ] = null ; king . setHasBeenMoved ( ) ; rook . setHasBeenMoved ( ) ; } for ( Move move : toBeSent . getMoves ( ) ) { if ( ChessLogic . checkingEnemy ( board , move . getToRow ( ) , move . getToColumn ( ) ) ) { move . setCheckingEnemy ( ) ; } } NetworkCommunicator . sendDataPackage ( socket , toBeSent ) ; moveOpponentPieceTask . setMouseClickEnabled ( false ) ; if ( ChessLogic . beingChecked ( board ) ) { JOptionPane . showMessageDialog ( this , "You<seq2seq4repair_space>are<seq2seq4repair_space>being<seq2seq4repair_space>checked!" ) ; } if ( endGame ) { System . exit ( 0 ) ; } } } repaint ( ) ; }

Fix:
if ( ( ( row == 0 ) && ( ( mostRecentlyMovedPiece . getType ( ) ) == ( ChessType . PAWN ) ) ) && ( ! endGame ) ) {