Buggy code:
} range . location = 0 ; range . length = numberOfGlyphs ; layoutManager . drawGlyphsForGlyphRange ( range , pt ) ; if ( ! defaultFg ) { range . location = 0 ; range . length = length ; layoutManager . removeTemporaryAttribute ( NSForegroundColorAttributeName , range ) ; } NSPoint point = new NSPoint ( ) ; for ( int j = 0 ; j < ( styles . length ) ; j ++ ) { TextLayout . StyleItem run = styles [ j ] ; TextStyle style = run . style ; if ( style == null ) continue ; boolean drawUnderline = ( style . underline ) && ( ! ( isUnderlineSupported ( style ) ) ) ; drawUnderline = drawUnderline && ( ( ( j + 1 ) == ( styles . length ) ) || ( ! ( style . isAdherentUnderline ( styles [ ( j + 1 ) ] . style ) ) ) ) ; boolean drawBorder = ( style . borderStyle ) != ( SWT . NONE ) ; drawBorder = drawBorder && ( ( ( j + 1 ) == ( styles . length ) ) || ( ! ( style . isAdherentBorder ( styles [ ( j + 1 ) ] . style ) ) ) ) ; if ( ( ! drawUnderline ) && ( ! drawBorder ) ) continue ; int end = ( ( j + 1 ) < ( styles . length ) ) ? translateOffset ( ( ( styles [ ( j + 1 ) ] . start ) - 1 ) ) : length ; for ( int i = 0 ; i < ( ( lineOffsets . length ) - 1 ) ; i ++ ) { int lineStart = untranslateOffset ( lineOffsets [ i ] ) ; int lineEnd = untranslateOffset ( ( ( lineOffsets [ ( i + 1 ) ] ) - 1 ) ) ; if ( drawUnderline ) { int start = run . start ; for ( int k = j ; ( k > 0 ) && ( style . isAdherentUnderline ( styles [ ( k - 1 ) ] . style ) ) ; k -- ) { start = styles [ ( k - 1 ) ] . start ; } start = translateOffset ( start ) ; if ( ! ( ( start > lineEnd ) || ( end < lineStart ) ) ) { range . location = Math . max ( lineStart , start ) ; range . length = ( ( Math . min ( lineEnd , end ) ) + 1 ) - ( range . location ) ; if ( ( range . length ) > 0 ) { int pRectCount = OS . malloc ( PTR_SIZEOF ) ; int pArray = layoutManager . rectArrayForCharacterRange ( range , range , textContainer , pRectCount ) ; int [ ] rectCount = new int [ 1 ] ; OS . memmove ( rectCount , pRectCount , PTR_SIZEOF ) ; OS . free ( pRectCount ) ; NSRect rect = new NSRect ( ) ; gc . handle . saveGraphicsState ( ) ; float baseline = layoutManager . typesetter ( ) . baselineOffsetInLayoutManager ( layoutManager , lineStart ) ; float [ ] color = null ; if ( ( style . underlineColor ) != null ) color = style . underlineColor . handle ; if ( ( color == null ) && ( ( style . foreground ) != null ) ) color = style . foreground . handle ; if ( color != null ) { NSColor . colorWithDeviceRed ( color [ 0 ] , color [ 1 ] , color [ 2 ] , color [ 3 ] ) . setStroke ( ) ; } for ( int k = 0 ; k < ( rectCount [ 0 ] ) ; k ++ , pArray += NSRect . sizeof ) { OS . memmove ( rect , pArray , sizeof ) ; float underlineX = ( pt . x ) + ( rect . x ) ; <START_BUG> float underlineY = ( ( ( pt . y ) + ( rect . y ) ) + ( rect . height ) ) - baseline ; <END_BUG> NSBezierPath path = NSBezierPath . bezierPath ( ) ; switch ( style . underlineStyle ) { case SWT . UNDERLINE_ERROR : { path . setLineWidth ( 2.0F ) ; path . setLineCapStyle ( NSRoundLineCapStyle ) ; path . setLineJoinStyle ( NSRoundLineJoinStyle ) ; path . setLineDash ( new float [ ] { 1 , 3.0F } , 2 , 0 ) ; point . x = underlineX ; point . y = underlineY + 0.5F ; path . moveToPoint ( point ) ; point . x = underlineX + ( rect . width ) ; point . y = underlineY + 0.5F ; path . lineToPoint ( point ) ; break ; } case SWT . UNDERLINE_SQUIGGLE : { gc . handle . setShouldAntialias ( false ) ; path . setLineWidth ( 1.0F ) ; path . setLineCapStyle ( NSButtLineCapStyle ) ; path . setLineJoinStyle ( NSMiterLineJoinStyle ) ; float lineBottom = ( ( pt . y ) + ( rect . y ) ) + ( rect . height ) ; float squigglyThickness = 1 ; float squigglyHeight = 2 * squigglyThickness ; float squigglyY = Math . min ( ( underlineY - ( squigglyHeight // 2 ) ) , ( ( lineBottom - squigglyHeight ) - 1 ) ) ; float [ ] points = computePolyline ( ( ( int ) ( underlineX ) ) , ( ( int ) ( squigglyY ) ) , ( ( int ) ( underlineX + ( rect . width ) ) ) , ( ( int ) ( squigglyY + squigglyHeight ) ) ) ; point . x = ( points [ 0 ] ) + 0.5F ;

Fix:
float underlineY = ( ( ( ( pt . y ) + ( rect . y ) ) + ( rect . height ) ) - baseline ) + 1 ;