Buggy code:
public class ExpandItem extends Item { ExpandBar parent ; Control control ; boolean expanded ; boolean hover ; int x ; int y ; int width ; int height ; int imageHeight ; int imageWidth ; static final int TEXT_INSET = 6 ; static final int BORDER = 1 ; static final int CHEVRON_SIZE = 24 ; public ExpandItem ( ExpandBar parent , int style ) { } public ExpandItem ( ExpandBar parent , int style , int index ) { } static ExpandBar checkNull ( ExpandBar control ) { } private void drawChevron ( int hDC , RECT rect ) { int oldBrush = OS . SelectObject ( hDC , OS . GetSysColorBrush ( COLOR_BTNFACE ) ) ; OS . PatBlt ( hDC , rect . left , rect . top , ( ( rect . right ) - ( rect . left ) ) , ( ( rect . bottom ) - ( rect . top ) ) , PATCOPY ) ; OS . SelectObject ( hDC , oldBrush ) ; rect . left += 4 ; rect . top += 4 ; rect . right -= 4 ; rect . bottom -= 4 ; <START_BUG> int hPen = OS . CreatePen ( PS_SOLID , 1 , parent . foreground ) ; <END_BUG> int oldPen = OS . SelectObject ( hDC , hPen ) ; int [ ] polyline1 ; int [ ] polyline2 ; if ( expanded ) { int px = ( rect . left ) + 5 ; int py = ( rect . top ) + 7 ; polyline1 = new int [ ] { px , py , px + 1 , py , px + 1 , py - 1 , px + 2 , py - 1 , px + 2 , py - 2 , px + 3 , py - 2 , px + 3 , py - 3 , px + 3 , py - 2 , px + 4 , py - 2 , px + 4 , py - 1 , px + 5 , py - 1 , px + 5 , py , px + 7 , py } ; py += 4 ; polyline2 = new int [ ] { px , py , px + 1 , py , px + 1 , py - 1 , px + 2 , py - 1 , px + 2 , py - 2 , px + 3 , py - 2 , px + 3 , py - 3 , px + 3 , py - 2 , px + 4 , py - 2 , px + 4 , py - 1 , px + 5 , py - 1 , px + 5 , py , px + 7 , py } ; } else { int px = ( rect . left ) + 5 ; int py = ( rect . top ) + 4 ; polyline1 = new int [ ] { px , py , px + 1 , py , px + 1 , py + 1 , px + 2 , py + 1 , px + 2 , py + 2 , px + 3 , py + 2 , px + 3 , py + 3 , px + 3 , py + 2 , px + 4 , py + 2 , px + 4 , py + 1 , px + 5 , py + 1 , px + 5 , py , px + 7 , py } ; py += 4 ; polyline2 = new int [ ] { px , py , px + 1 , py , px + 1 , py + 1 , px + 2 , py + 1 , px + 2 , py + 2 , px + 3 , py + 2 , px + 3 , py + 3 , px + 3 , py + 2 , px + 4 , py + 2 , px + 4 , py + 1 , px + 5 , py + 1 , px + 5 , py , px + 7 , py } ; } OS . Polyline ( hDC , polyline1 , ( ( polyline1 . length ) // 2 ) ) ; OS . Polyline ( hDC , polyline2 , ( ( polyline2 . length ) // 2 ) ) ; if ( hover ) { int whitePen = OS . CreatePen ( PS_SOLID , 1 , OS . GetSysColor ( COLOR_3DHILIGHT ) ) ; int darkGrayPen = OS . CreatePen ( PS_SOLID , 1 , OS . GetSysColor ( COLOR_3DSHADOW ) ) ; OS . SelectObject ( hDC , whitePen ) ; int [ ] points1 = new int [ ] { rect . left , rect . bottom , rect . left , rect . top , rect . right , rect . top } ; OS . Polyline ( hDC , points1 , ( ( points1 . length ) // 2 ) ) ; OS . SelectObject ( hDC , darkGrayPen ) ; int [ ] points2 = new int [ ] { rect . right , rect . top , rect . right , rect . bottom , rect . left , rect . bottom } ; OS . Polyline ( hDC , points2 , ( ( points2 . length ) // 2 ) ) ; OS . SelectObject ( hDC , oldPen ) ; OS . DeleteObject ( whitePen ) ; OS . DeleteObject ( darkGrayPen ) ; } else { OS . SelectObject ( hDC , oldPen ) ; } OS . DeleteObject ( hPen ) ; } void drawItem ( GC gc , int hTheme , RECT clipRect , boolean drawFocus ) { } void destroyWidget ( ) { } public Control getControl ( ) { } public boolean getExpanded ( ) { }

Fix:
int hPen = OS . CreatePen ( PS_SOLID , 1 , parent . getForegroundPixel ( ) ) ;