Buggy code:
} if ( lpXform != null ) { OS . SetGraphicsMode ( hdc , GM_ADVANCED ) ; OS . SetWorldTransform ( hdc , lpXform ) ; } if ( clipRgn != 0 ) { OS . SelectClipRgn ( hdc , clipRgn ) ; OS . DeleteObject ( clipRgn ) ; } } boolean hasSelection = ( ( selectionStart <= selectionEnd ) && ( selectionStart != ( - 1 ) ) ) && ( selectionEnd != ( - 1 ) ) ; if ( hasSelection || ( ( flags & 4 ) != 0 ) ) { selectionStart = Math . min ( Math . max ( 0 , selectionStart ) , ( length - 1 ) ) ; selectionEnd = Math . min ( Math . max ( 0 , selectionEnd ) , ( length - 1 ) ) ; if ( selectionForeground == null ) selectionForeground = device . getSystemColor ( COLOR_LIST_SELECTION_TEXT ) ; if ( selectionBackground == null ) selectionBackground = device . getSystemColor ( COLOR_LIST_SELECTION ) ; selectionStart = translateOffset ( selectionStart ) ; selectionEnd = translateOffset ( selectionEnd ) ; } RECT rect = new RECT ( ) ; int selBrush = 0 ; int selPen = 0 ; int selBrushFg = 0 ; if ( hasSelection || ( ( flags & 4 ) != 0 ) ) { if ( gdip ) { int bg = selectionBackground . handle ; int argb = ( ( ( ( alpha & 255 ) << 24 ) | ( ( bg > > 16 ) & 255 ) ) | ( bg & 65280 ) ) | ( ( bg & 255 ) << 16 ) ; int color = Gdip . Color_new ( argb ) ; selBrush = Gdip . SolidBrush_new ( color ) ; Gdip . Color_delete ( color ) ; int fg = selectionForeground . handle ; argb = ( ( ( ( alpha & 255 ) << 24 ) | ( ( fg > > 16 ) & 255 ) ) | ( fg & 65280 ) ) | ( ( fg & 255 ) << 16 ) ; color = Gdip . Color_new ( argb ) ; selBrushFg = Gdip . SolidBrush_new ( color ) ; selPen = Gdip . Pen_new ( selBrushFg , 1 ) ; Gdip . Color_delete ( color ) ; } else { selBrush = OS . CreateSolidBrush ( selectionBackground . handle ) ; selPen = OS . CreatePen ( BS_SOLID , 1 , selectionForeground . handle ) ; } } OS . SetBkMode ( hdc , TRANSPARENT ) ; for ( int line = 0 ; line < ( runs . length ) ; line ++ ) { int drawX = x + ( getLineIndent ( line ) ) ; int drawY = y + ( lineY [ line ] ) ; if ( drawX > ( ( clip . x ) + ( clip . width ) ) ) continue ; if ( ( drawX + ( lineWidth [ line ] ) ) < ( clip . x ) ) continue ; TextLayout . StyleItem [ ] lineRuns = runs [ line ] ; int baseline = Math . max ( 0 , this . ascent ) ; for ( int i = 0 ; i < ( lineRuns . length ) ; i ++ ) { baseline = Math . max ( baseline , lineRuns [ i ] . ascent ) ; } int lineHeight = ( lineY [ ( line + 1 ) ] ) - ( lineY [ line ] ) ; int alignmentX = drawX ; <START_BUG> if ( hasSelection || ( ( flags & 4 ) != 0 ) ) { <END_BUG> boolean extents = false ; if ( ( line == ( ( runs . length ) - 1 ) ) && ( ( flags & 4 ) != 0 ) ) { extents = true ; } else { TextLayout . StyleItem run = lineRuns [ ( ( lineRuns . length ) - 1 ) ] ; if ( ( run . lineBreak ) && ( ! ( run . softBreak ) ) ) { if ( ( selectionStart <= ( run . start ) ) && ( ( run . start ) <= selectionEnd ) ) extents = true ; } else { int endOffset = ( ( run . start ) + ( run . length ) ) - 1 ; if ( ( ( selectionStart <= endOffset ) && ( endOffset < selectionEnd ) ) && ( ( flags & 2 ) != 0 ) ) { extents = true ; } } } if ( extents ) { int selX = drawX + ( lineWidth [ line ] ) ; int width = ( ( flags & 2 ) != 0 ) ? 10000 : 10 ; if ( gdip ) { Gdip . Graphics_FillRectangle ( gdipGraphics , selBrush , selX , drawY , width , ( lineHeight - ( lineSpacing ) ) ) ; } else { OS . SelectObject ( hdc , selBrush ) ; OS . PatBlt ( hdc , selX , drawY , width , ( lineHeight - ( lineSpacing ) ) , PATCOPY ) ; } } } for ( int i = 0 ; i < ( lineRuns . length ) ; i ++ ) { TextLayout . StyleItem run = lineRuns [ i ] ; if ( ( run . length ) == 0 ) continue ; if ( drawX > ( ( clip . x ) + ( clip . width ) ) ) break ; if ( ( drawX + ( run . width ) ) >= ( clip . x ) ) { if ( ( ! ( run . lineBreak ) ) || ( run . softBreak ) ) { int end = ( ( run . start ) + ( run . length ) ) - 1 ;

Fix:
if ( ( flags != 0 ) && ( hasSelection || ( ( flags & 4 ) != 0 ) ) ) {