Buggy code:
boolean hasComment = false ; boolean hasLineComment = false ; boolean hasWhitespace = false ; int count = 0 ; while ( true ) { this . currentToken = this . scanner . getNextToken ( ) ; switch ( this . currentToken ) { case TerminalTokens . TokenNameWHITESPACE : char [ ] whiteSpaces = this . scanner . getCurrentTokenSource ( ) ; count = 0 ; for ( int i = 0 , max = whiteSpaces . length ; i < max ; i ++ ) { switch ( whiteSpaces [ i ] ) { case '\r' : if ( ( i + 1 ) < max ) { if ( ( whiteSpaces [ ( i + 1 ) ] ) == '\n' ) { i ++ ; } } count ++ ; break ; case '\n' : count ++ ; } } if ( count == 0 ) { hasWhitespace = true ; addDeleteEdit ( this . scanner . getCurrentTokenStartPosition ( ) , this . scanner . getCurrentTokenEndPosition ( ) ) ; } else if ( hasComment ) { if ( count == 1 ) { this . printNewLine ( this . scanner . getCurrentTokenStartPosition ( ) ) ; } else { preserveEmptyLines ( ( count - 1 ) , this . scanner . getCurrentTokenStartPosition ( ) ) ; } addDeleteEdit ( this . scanner . getCurrentTokenStartPosition ( ) , this . scanner . getCurrentTokenEndPosition ( ) ) ; } else if ( hasLineComment ) { this . preserveEmptyLines ( count , this . scanner . getCurrentTokenStartPosition ( ) ) ; addDeleteEdit ( this . scanner . getCurrentTokenStartPosition ( ) , this . scanner . getCurrentTokenEndPosition ( ) ) ; } else { addDeleteEdit ( this . scanner . getCurrentTokenStartPosition ( ) , this . scanner . getCurrentTokenEndPosition ( ) ) ; } currentTokenStartPosition = this . scanner . currentPosition ; break ; case TerminalTokens . TokenNameCOMMENT_LINE : if ( count >= 1 ) { if ( count > 1 ) { preserveEmptyLines ( ( count - 1 ) , this . scanner . getCurrentTokenStartPosition ( ) ) ; } else if ( count == 1 ) { printNewLine ( this . scanner . getCurrentTokenStartPosition ( ) ) ; } } else if ( hasWhitespace ) { space ( ) ; } hasWhitespace = false ; this . printCommentLine ( this . scanner . getRawTokenSource ( ) ) ; currentTokenStartPosition = this . scanner . currentPosition ; hasLineComment = true ; count = 0 ; break ; case TerminalTokens . TokenNameCOMMENT_BLOCK : if ( count >= 1 ) { if ( count > 1 ) { preserveEmptyLines ( ( count - 1 ) , this . scanner . getCurrentTokenStartPosition ( ) ) ; } else if ( count == 1 ) { printNewLine ( this . scanner . getCurrentTokenStartPosition ( ) ) ; } } else if ( hasWhitespace ) { space ( ) ; } hasWhitespace = false ; this . printBlockComment ( this . scanner . getRawTokenSource ( ) , false ) ; currentTokenStartPosition = this . scanner . currentPosition ; hasLineComment = false ; hasComment = true ; count = 0 ; break ; case TerminalTokens . TokenNameCOMMENT_JAVADOC : if ( count >= 1 ) { if ( count > 1 ) { preserveEmptyLines ( ( count - 1 ) , this . scanner . getCurrentTokenStartPosition ( ) ) ; } else if ( count == 1 ) { printNewLine ( this . scanner . getCurrentTokenStartPosition ( ) ) ; } } else if ( hasWhitespace ) { space ( ) ; } hasWhitespace = false ; this . printBlockComment ( this . scanner . getRawTokenSource ( ) , true ) ; currentTokenStartPosition = this . scanner . currentPosition ; hasLineComment = false ; hasComment = true ; count = 0 ; break ; case TerminalTokens . TokenNameSEMICOLON : char [ ] currentTokenSource = this . scanner . getRawTokenSource ( ) ; this . print ( currentTokenSource , this . formatter . preferences . insert_space_before_semicolon ) ; break ; case TerminalTokens . TokenNameEOF : <START_BUG> if ( ( count >= 1 ) || ( this . formatter . preferences . insert_new_line_at_end_of_file ) ) { <END_BUG> this . printNewLine ( this . scannerEndPosition ) ; } return ; default : this . scanner . resetTo ( currentTokenStartPosition , ( ( this . scannerEndPosition ) - 1 ) ) ; return ; } } } catch ( InvalidInputException e ) { throw new AbortFormatting ( e ) ; } } public void printComment ( ) { } private void printCommentLine ( char [ ] s ) { } public void printEmptyLines ( int linesNumber ) { } private void printEmptyLines ( int linesNumber , int insertPosition ) { } private void printIndentationIfNecessary ( ) { } private void printIndentationIfNecessary ( StringBuffer buffer ) { } public void printModifiers ( Annotation [ ] annotations , ASTVisitor visitor ) { } public void printNewLine ( ) { } public void printNewLine ( int insertPosition ) { } public void printNextToken ( int expectedTokenType ) { } public void printNextToken ( int expectedTokenType , boolean considerSpaceIfAny ) { } public void printNextToken ( int [ ] expectedTokenTypes ) { } public void printNextToken ( int [ ] expectedTokenTypes , boolean considerSpaceIfAny ) { } public void printQualifiedReference ( int sourceEnd ) { } private void printRule ( StringBuffer stringBuffer ) { } public void printTrailingComment ( ) { } void redoAlignment ( AlignmentException e ) { } void redoMemberAlignment ( AlignmentException e ) { } public void reset ( ) { } private void resetAt ( Location location ) { } private void resize ( ) { } public void setLineSeparatorAndIdentationLevel ( DefaultCodeFormatterOptions preferences ) { } public void space ( ) { } private void tab ( StringBuffer buffer ) { } public String toString ( ) { } public void unIndent ( ) { } }

Fix:
if ( ( count >= 1 ) || ( this . formatter . preferences . insert_new_line_at_end_of_file_if_missing ) ) {