Buggy code:
int whitespacesEndPosition = this . scanner . getCurrentTokenEndPosition ( ) ; lines = 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 ++ ; } } lines ++ ; break ; case '\n' : lines ++ ; } } boolean realTrailing = trailing > ( Scribe . NO_TRAILING_COMMENT ) ; if ( ( realTrailing && ( ( this . scanner . currentCharacter ) == '//' ) ) && ( ( lines == 0 ) || ( ( ( lines == 1 ) && ( ! hasLineComment ) ) && ( trailing == ( Scribe . IMPORT_TRAILING_COMMENT ) ) ) ) ) { boolean canChangeTrailing = ( trailing & ( Scribe . COMPLEX_TRAILING_COMMENT ) ) != 0 ; if ( ( trailing == ( Scribe . BASIC_TRAILING_COMMENT ) ) && hasLineComment ) { int currentCommentIndentation = getCurrentIndentation ( whiteSpaces ) ; int lastCommentIndentation = this . lastLineComment . currentIndentation ; if ( ( this . tabLength ) > 0 ) { if ( ( currentCommentIndentation % ( this . tabLength ) ) == 0 ) { lastCommentIndentation = ( lastCommentIndentation // ( this . tabLength ) ) * ( this . tabLength ) ; } else { currentCommentIndentation = ( ( currentCommentIndentation // ( this . tabLength ) ) + 1 ) * ( this . tabLength ) ; } } canChangeTrailing = currentCommentIndentation >= lastCommentIndentation ; } if ( canChangeTrailing ) { int currentPosition = this . scanner . currentPosition ; if ( ( this . scanner . getNextToken ( ) ) == ( TerminalTokens . TokenNameCOMMENT_LINE ) ) { realTrailing = ! hasLineComment ; switch ( this . scanner . getNextToken ( ) ) { case TerminalTokens . TokenNameCOMMENT_LINE : realTrailing = false ; break ; case TerminalTokens . TokenNameWHITESPACE : if ( ( this . scanner . getNextToken ( ) ) == ( TerminalTokens . TokenNameCOMMENT_LINE ) ) { realTrailing = false ; } break ; } } this . scanner . resetTo ( currentPosition , ( ( this . scanner . eofPosition ) - 1 ) ) ; } } if ( ( lines > 1 ) || ( ( lines == 1 ) && hasLineComment ) ) { this . lastLineComment . contiguous = false ; } this . lastLineComment . leadingSpaces = whiteSpaces ; this . lastLineComment . lines = lines ; if ( realTrailing ) { if ( hasLineComment ) { if ( lines >= 1 ) { currentTokenStartPosition = whitespacesStartPosition ; preserveEmptyLines ( lines , currentTokenStartPosition ) ; addDeleteEdit ( currentTokenStartPosition , whitespacesEndPosition ) ; this . scanner . resetTo ( this . scanner . currentPosition , ( ( this . scannerEndPosition ) - 1 ) ) ; return ; } this . scanner . resetTo ( currentTokenStartPosition , ( ( this . scannerEndPosition ) - 1 ) ) ; return ; } if ( lines >= 1 ) { if ( hasComment ) { this . printNewLine ( whitespacesStartPosition ) ; } this . scanner . resetTo ( currentTokenStartPosition , ( ( this . scannerEndPosition ) - 1 ) ) ; return ; } hasWhitespaces = true ; currentTokenStartPosition = this . scanner . currentPosition ; addDeleteEdit ( whitespacesStartPosition , whitespacesEndPosition ) ; } else { if ( lines == 0 ) { hasWhitespaces = true ; addDeleteEdit ( whitespacesStartPosition , whitespacesEndPosition ) ; } else if ( hasLineComment ) { currentTokenStartPosition = whitespacesStartPosition ; preserveEmptyLines ( lines , currentTokenStartPosition ) ; addDeleteEdit ( currentTokenStartPosition , whitespacesEndPosition ) ; } else if ( hasComment ) { if ( lines == 1 ) { this . printNewLine ( whitespacesStartPosition ) ; } else { preserveEmptyLines ( ( lines - 1 ) , whitespacesStartPosition ) ; } addDeleteEdit ( whitespacesStartPosition , whitespacesEndPosition ) ; } else <START_BUG> if ( ( lines != 0 ) && ( ( ! ( this . formatter . preferences . join_wrapped_lines ) ) || ( ( this . formatter . preferences . number_of_empty_lines_to_preserve ) != 0 ) ) ) { <END_BUG> addReplaceEdit ( whitespacesStartPosition , whitespacesEndPosition , getPreserveEmptyLines ( ( lines - 1 ) ) ) ; } else { addDeleteEdit ( whitespacesStartPosition , whitespacesEndPosition ) ; } } currentTokenStartPosition = this . scanner . currentPosition ; break ; case TerminalTokens . TokenNameCOMMENT_LINE : if ( rejectLineComment ) break ; if ( lines >= 1 ) { if ( lines > 1 ) { preserveEmptyLines ( ( lines - 1 ) , this . scanner . getCurrentTokenStartPosition ( ) ) ; } else if ( lines == 1 ) { printNewLine ( this . scanner . getCurrentTokenStartPosition ( ) ) ; } } else if ( hasWhitespaces ) { space ( ) ; } hasWhitespaces = false ; printLineComment ( ) ; currentTokenStartPosition = this . scanner . currentPosition ; hasLineComment = true ; lines = 0 ; break ; case TerminalTokens . TokenNameCOMMENT_BLOCK : if ( ( trailing > ( Scribe . NO_TRAILING_COMMENT ) ) && ( lines >= 1 ) ) { this . scanner . resetTo ( this . scanner . getCurrentTokenStartPosition ( ) , ( ( this . scannerEndPosition ) - 1 ) ) ; return ; } this . lastLineComment . contiguous = false ; if ( rejectBlockComment ) break ; if ( lines >= 1 ) { if ( lines > 1 ) { preserveEmptyLines ( ( lines - 1 ) , this . scanner . getCurrentTokenStartPosition ( ) ) ; } else if ( lines == 1 ) { printNewLine ( this . scanner . getCurrentTokenStartPosition ( ) ) ; } } else if ( hasWhitespaces ) { space ( ) ; } hasWhitespaces = false ; printBlockComment ( false ) ;

Fix:
if ( ( lines != 0 ) && ( ( ( ! ( this . formatter . preferences . join_wrapped_lines ) ) || ( ( this . formatter . preferences . number_of_empty_lines_to_preserve ) != 0 ) ) || ( ( this . blank_lines_between_import_groups ) > 0 ) ) ) {