Buggy code:
public final class GC extends Resource { public int handle ; Drawable drawable ; GCData data ; static final int FOREGROUND = 1 << 0 ; static final int BACKGROUND = 1 << 1 ; static final int FONT = 1 << 2 ; static final int LINE_STYLE = 1 << 3 ; static final int LINE_WIDTH = 1 << 4 ; static final int LINE_CAP = 1 << 5 ; static final int LINE_JOIN = 1 << 6 ; static final int LINE_MITERLIMIT = 1 << 7 ; static final int FOREGROUND_TEXT = 1 << 8 ; static final int BACKGROUND_TEXT = 1 << 9 ; static final int BRUSH = 1 << 10 ; static final int PEN = 1 << 11 ; static final int NULL_BRUSH = 1 << 12 ; static final int NULL_PEN = 1 << 13 ; static final int DRAW = ( ( ( ( ( ( ( GC . FOREGROUND ) | ( GC . LINE_STYLE ) ) | ( GC . LINE_WIDTH ) ) | ( GC . LINE_CAP ) ) | ( GC . LINE_JOIN ) ) | ( GC . LINE_MITERLIMIT ) ) | ( GC . PEN ) ) | ( GC . NULL_BRUSH ) ; static final int FILL = ( ( GC . BACKGROUND ) | ( GC . BRUSH ) ) | ( GC . NULL_PEN ) ; static final float [ ] LINE_DOT_ZERO = new float [ ] { 3 , 3 } ; static final float [ ] LINE_DASH_ZERO = new float [ ] { 18 , 6 } ; static final float [ ] LINE_DASHDOT_ZERO = new float [ ] { 9 , 6 , 3 , 6 } ; static final float [ ] LINE_DASHDOTDOT_ZERO = new float [ ] { 9 , 3 , 3 , 3 , 3 , 3 } ; GC ( ) { } public GC ( Drawable drawable ) { } public GC ( Drawable drawable , int style ) { } static int checkStyle ( int style ) { } void checkGC ( int mask ) { int state = data . state ; if ( ( state & mask ) == mask ) return ; state = ( state ^ mask ) & mask ; data . state |= mask ; int gdipGraphics = data . gdipGraphics ; if ( gdipGraphics != 0 ) { int pen = data . gdipPen ; float width = data . lineWidth ; <START_BUG> if ( ( state & ( GC . FOREGROUND ) ) != 0 ) { <END_BUG> if ( ( data . gdipFgBrush ) != 0 ) Gdip . SolidBrush_delete ( data . gdipFgBrush ) ; data . gdipFgBrush = 0 ; int brush ; Pattern pattern = data . foregroundPattern ; if ( pattern != null ) { brush = pattern . handle ; } else { int foreground = data . foreground ; int rgb = ( ( ( foreground > > 16 ) & 255 ) | ( foreground & 65280 ) ) | ( ( foreground & 255 ) << 16 ) ; int color = Gdip . Color_new ( ( ( ( data . alpha ) << 24 ) | rgb ) ) ; if ( color == 0 ) SWT . error ( ERROR_NO_HANDLES ) ; brush = Gdip . SolidBrush_new ( color ) ; if ( brush == 0 ) SWT . error ( ERROR_NO_HANDLES ) ; Gdip . Color_delete ( color ) ; data . gdipFgBrush = brush ; brush = data . gdipFgBrush ; } if ( pen != 0 ) { Gdip . Pen_SetBrush ( pen , brush ) ; } else { pen = data . gdipPen = Gdip . Pen_new ( brush , width ) ; } } if ( ( state & ( GC . LINE_WIDTH ) ) != 0 ) { Gdip . Pen_SetWidth ( pen , width ) ; switch ( data . lineStyle ) { case SWT . LINE_CUSTOM : state |= GC . LINE_STYLE ; } } if ( ( state & ( GC . LINE_STYLE ) ) != 0 ) { float [ ] dashes = null ; float dashOffset = 0 ; int dashStyle = Gdip . DashStyleSolid ; switch ( data . lineStyle ) { case SWT . LINE_SOLID : break ; case SWT . LINE_DOT : dashStyle = Gdip . DashStyleDot ; if ( width == 0 ) dashes = GC . LINE_DOT_ZERO ; break ; case SWT . LINE_DASH : dashStyle = Gdip . DashStyleDash ; if ( width == 0 ) dashes = GC . LINE_DASH_ZERO ; break ; case SWT . LINE_DASHDOT : dashStyle = Gdip . DashStyleDashDot ; if ( width == 0 ) dashes = GC . LINE_DASHDOT_ZERO ; break ; case SWT . LINE_DASHDOTDOT : dashStyle = Gdip . DashStyleDashDotDot ; if ( width == 0 ) dashes = GC . LINE_DASHDOTDOT_ZERO ; break ; case SWT . LINE_CUSTOM : { if ( ( data . lineDashes ) != null ) { dashOffset = ( data . lineDashesOffset ) // ( Math . max ( 1 , width ) ) ; dashes = new float [ ( data . lineDashes . length ) * 2 ] ; for ( int i = 0 ; i < ( data . lineDashes . length ) ; i ++ ) { float dash = ( data . lineDashes [ i ] ) // ( Math . max ( 1 , width ) ) ; dashes [ i ] = dash ; dashes [ ( i + ( data . lineDashes . length ) ) ] = dash ; } } } } if ( dashes != null ) { Gdip . Pen_SetDashPattern ( pen , dashes , dashes . length ) ; Gdip . Pen_SetDashStyle ( pen , DashStyleCustom ) ; Gdip . Pen_SetDashOffset ( pen , dashOffset ) ; }

Fix:
if ( ( ( state & ( GC . FOREGROUND ) ) != 0 ) || ( ( pen == 0 ) && ( ( state & ( ( ( ( ( GC . LINE_WIDTH ) | ( GC . LINE_STYLE ) ) | ( GC . LINE_MITERLIMIT ) ) | ( GC . LINE_JOIN ) ) | ( GC . LINE_CAP ) ) ) != 0 ) ) ) {