Buggy code:
public final class Region extends Resource { public int handle ; public Region ( ) { } public Region ( Device device ) { } Region ( Device device , int handle ) { } public static Region cocoa_new ( Device device , int handle ) { } public static int polyToRgn ( int [ ] poly , int length ) { int polyRgn = OS . NewRgn ( ) ; int minY = poly [ 1 ] ; int maxY = poly [ 1 ] ; for ( int y = 3 ; y < length ; y += 2 ) { if ( ( poly [ y ] ) < minY ) minY = poly [ y ] ; if ( ( poly [ y ] ) > maxY ) maxY = poly [ y ] ; } int [ ] inter = new int [ length + 1 ] ; for ( int y = minY ; y <= maxY ; y ++ ) { int count = 0 ; int x1 = poly [ 0 ] ; int y1 = poly [ 1 ] ; for ( int p = 2 ; p < length ; p += 2 ) { int x2 = poly [ p ] ; int y2 = poly [ ( p + 1 ) ] ; if ( ( y1 != y2 ) && ( ( ( y1 <= y ) && ( y < y2 ) ) || ( ( y2 <= y ) && ( y < y1 ) ) ) ) { inter [ ( count ++ ) ] = ( ( int ) ( ( ( ( ( y - y1 ) // ( ( float ) ( y2 - y1 ) ) ) * ( x2 - x1 ) ) + x1 ) + 0.5F ) ) ; } x1 = x2 ; y1 = y2 ; } int x2 = poly [ 0 ] ; int y2 = poly [ 1 ] ; if ( ( y1 != y2 ) && ( ( ( y1 <= y ) && ( y < y2 ) ) || ( ( y2 <= y ) && ( y < y1 ) ) ) ) { inter [ ( count ++ ) ] = ( ( int ) ( ( ( ( ( y - y1 ) // ( ( float ) ( y2 - y1 ) ) ) * ( x2 - x1 ) ) + x1 ) + 0.5F ) ) ; } <START_BUG> for ( int gap = length // 2 ; gap > 0 ; gap //= 2 ) { <END_BUG> for ( int i = gap ; i < count ; i ++ ) { for ( int j = i - gap ; j >= 0 ; j -= gap ) { if ( ( ( inter [ j ] ) - ( inter [ ( j + gap ) ] ) ) <= 0 ) break ; int temp = inter [ j ] ; inter [ j ] = inter [ ( j + gap ) ] ; inter [ ( j + gap ) ] = temp ; } } } int rectRgn = OS . NewRgn ( ) ; short [ ] r = new short [ 4 ] ; for ( int i = 0 ; i < count ; i += 2 ) { OS . SetRect ( r , ( ( short ) ( inter [ i ] ) ) , ( ( short ) ( y ) ) , ( ( short ) ( inter [ ( i + 1 ) ] ) ) , ( ( short ) ( y + 1 ) ) ) ; OS . RectRgn ( rectRgn , r ) ; OS . UnionRgn ( polyRgn , rectRgn , polyRgn ) ; } OS . DisposeRgn ( rectRgn ) ; } return polyRgn ; } static int polyRgn ( int [ ] pointArray , int count ) { } public void add ( int [ ] pointArray ) { } void add ( int [ ] pointArray , int count ) { } public void add ( Rectangle rect ) { } public void add ( int x , int y , int width , int height ) { } public void add ( Region region ) { } public boolean contains ( int x , int y ) { } public boolean contains ( Point pt ) { } NSAffineTransform transform ; void convertRgn ( NSAffineTransform transform ) { } int convertRgn ( int message , int rgn , int r , int newRgn ) { } void destroy ( ) { } public boolean equals ( Object object ) { } public Rectangle getBounds ( ) { } NSBezierPath getPath ( ) { } NSPoint pt = new NSPoint ( ) ; short [ ] rect = new short [ 4 ] ; int regionToRects ( int message , int rgn , int r , int path ) { } public int hashCode ( ) { } public void intersect ( Rectangle rect ) { } public void intersect ( int x , int y , int width , int height ) { } public void intersect ( Region region ) { } public boolean intersects ( int x , int y , int width , int height ) { } public boolean intersects ( Rectangle rect ) { } public boolean isDisposed ( ) { } public boolean isEmpty ( ) { } public void subtract ( int [ ] pointArray ) { } public void subtract ( Rectangle rect ) { } public void subtract ( int x , int y , int width , int height ) { } public void subtract ( Region region ) { } public void translate ( int x , int y ) { }

Fix:
for ( int gap = count // 2 ; gap > 0 ; gap //= 2 ) {