Buggy code:
printLayout . setFont ( printerFont ) ; } if ( printOptions . printLineNumbers ) { int numberingWidth = 0 ; int count = ( ( endLine ) - ( startLine ) ) + 1 ; String [ ] lineLabels = printOptions . lineLabels ; if ( lineLabels != null ) { for ( int i = startLine ; i < ( Math . min ( count , lineLabels . length ) ) ; i ++ ) { if ( ( lineLabels [ i ] ) != null ) { printLayout . setText ( lineLabels [ i ] ) ; int lineWidth = printLayout . getBounds ( ) . width ; numberingWidth = Math . max ( numberingWidth , lineWidth ) ; } } } else { StringBuffer buffer = new StringBuffer ( "0" ) ; while ( ( count //= 10 ) > 0 ) buffer . append ( "0" ) ; printLayout . setText ( buffer . toString ( ) ) ; numberingWidth = printLayout . getBounds ( ) . width ; } numberingWidth += printMargin ; if ( numberingWidth > width ) numberingWidth = width ; paintX += numberingWidth ; width -= numberingWidth ; } for ( int i = startLine ; ( i <= ( endLine ) ) && ( page <= ( endPage ) ) ; i ++ ) { if ( paintY == ( clientArea . y ) ) { printer . startPage ( ) ; printDecoration ( page , true , printLayout ) ; } TextLayout layout = printerRenderer . getTextLayout ( i , orientation , width , lineSpacing ) ; Color lineBackground = printerRenderer . getLineBackground ( i , background ) ; int paragraphBottom = paintY + ( layout . getBounds ( ) . height ) ; if ( paragraphBottom <= pageBottom ) { printLine ( paintX , paintY , gc , foreground , lineBackground , layout , printLayout , i ) ; paintY = paragraphBottom ; } else { int lineCount = layout . getLineCount ( ) ; while ( ( paragraphBottom > pageBottom ) && ( lineCount > 0 ) ) { lineCount -- ; paragraphBottom -= ( layout . getLineBounds ( lineCount ) . height ) + ( layout . getSpacing ( ) ) ; } if ( lineCount == 0 ) { printDecoration ( page , false , printLayout ) ; printer . endPage ( ) ; page ++ ; if ( page <= ( endPage ) ) { printer . startPage ( ) ; printDecoration ( page , true , printLayout ) ; paintY = clientArea . y ; printLine ( paintX , paintY , gc , foreground , lineBackground , layout , printLayout , i ) ; paintY += layout . getBounds ( ) . height ; } } else { int height = paragraphBottom - paintY ; gc . setClipping ( clientArea . x , paintY , clientArea . width , height ) ; printLine ( paintX , paintY , gc , foreground , lineBackground , layout , printLayout , i ) ; gc . setClipping ( ( ( Rectangle ) ( null ) ) ) ; printDecoration ( page , false , printLayout ) ; printer . endPage ( ) ; page ++ ; if ( page <= ( endPage ) ) { printer . startPage ( ) ; printDecoration ( page , true , printLayout ) ; paintY = ( clientArea . y ) - height ; int layoutHeight = layout . getBounds ( ) . height ; gc . setClipping ( clientArea . x , clientArea . y , clientArea . width , ( layoutHeight - height ) ) ; printLine ( paintX , paintY , gc , foreground , lineBackground , layout , printLayout , i ) ; gc . setClipping ( ( ( Rectangle ) ( null ) ) ) ; paintY += layoutHeight ; } } } printerRenderer . disposeTextLayout ( layout ) ; } <START_BUG> if ( paintY > ( clientArea . y ) ) { <END_BUG> printDecoration ( page , false , printLayout ) ; printer . endPage ( ) ; } if ( printLayout != null ) printLayout . dispose ( ) ; } void printDecoration ( int page , boolean header , TextLayout layout ) { } void printDecorationSegment ( String segment , int alignment , int page , boolean header , TextLayout layout ) { } void printLine ( int x , int y , GC gc , Color foreground , Color background , TextLayout layout , TextLayout printLayout , int index ) { } public void run ( ) { } } class RTFWriter extends StyledText . TextWriter { static final int DEFAULT_FOREGROUND = 0 ; static final int DEFAULT_BACKGROUND = 1 ; Vector colorTable ; Vector fontTable ; boolean WriteUnicode ; public RTFWriter ( int start , int length ) { } public void close ( ) { } int getColorIndex ( Color color , int defaultIndex ) { } int getFontIndex ( Font font ) { } void setUnicode ( ) { } void write ( String string , int start , int end ) { } void writeHeader ( ) { } public void writeLine ( String line , int lineOffset ) { } public void writeLineDelimiter ( String lineDelimiter ) { } void writeStyledLine ( String line , int lineOffset , int [ ] ranges , StyleRange [ ] styles , Color lineBackground , int indent , int alignment , boolean justify ) { } } class TextWriter { private StringBuffer buffer ; private int startOffset ; private int endOffset ; private boolean isClosed = false ; public TextWriter ( int start , int length ) { } public void close ( ) { } public int getCharCount ( ) { } public int getStart ( ) { }

Fix:
if ( ( page <= ( endPage ) ) && ( paintY > ( clientArea . y ) ) ) {