Buggy code:
public class TestGeo3DPoint extends LuceneTestCase { private static Codec getCodec ( ) { } public void testBasic ( ) throws Exception { } private static double toRadians ( double degrees ) { } private static class Cell { static int nextCellID ; final TestGeo3DPoint . Cell parent ; final int cellID ; final int xMinEnc ; final int xMaxEnc ; final int yMinEnc ; final int yMaxEnc ; final int zMinEnc ; final int zMaxEnc ; final int splitCount ; public Cell ( TestGeo3DPoint . Cell parent , int xMinEnc , int xMaxEnc , int yMinEnc , int yMaxEnc , int zMinEnc , int zMaxEnc , int splitCount ) { } public boolean contains ( GeoPoint point ) { } @ Override public String toString ( ) { } } private static double quantize ( double xyzValue ) { } private static GeoPoint quantize ( GeoPoint point ) { } public void testGeo3DRelations ( ) throws Exception { } public void testRandomTiny ( ) throws Exception { } public void testRandomMedium ( ) throws Exception { } @ Nightly public void testRandomBig ( ) throws Exception { } private void doTestRandom ( int count ) throws Exception { } public void testPolygonOrdering ( ) { } private static final double MEAN_EARTH_RADIUS_METERS = PlanetModel . WGS84_MEAN ; private static Query random3DQuery ( final String field ) { } private static GeoShape randomShape ( ) { } private static void verify ( double [ ] lats , double [ ] lons ) throws Exception { } public void testToString ( ) { } public void testShapeQueryToString ( ) { } private static Directory getDirectory ( ) { } public void testEquals ( ) { } public void testComplexPolygons ( ) { } protected static double MINIMUM_EDGE_ANGLE = TestGeo3DPoint . toRadians ( 5.0 ) ; protected static double MINIMUM_ARC_ANGLE = TestGeo3DPoint . toRadians ( 1.0 ) ; protected static Polygon makePoly ( final PlanetModel pm , final GeoPoint pole , final boolean clockwiseDesired , final boolean createHoles ) { } protected static List < GeoPoint > convertToPoints ( final PlanetModel pm , final GeoPoint pole , final double [ ] angles , final double [ ] arcDistances ) { } protected static GeoPoint createPoint ( final PlanetModel pm , final double angle , final double arcDistance , final double sinLatitude , final double cosLatitude , final double sinLongitude , final double cosLongitude ) { } protected static boolean verifyPolygon ( final PlanetModel pm , final Polygon polygon , final GeoPolygon outsidePolygon ) { } protected static int legalIndex ( int index , int size ) { } public void testEncodeDecodeCeil ( ) throws Exception { } public void testEncodeDecodeRoundsDown ( ) throws Exception { } public void testEncodeDecodeIsStable ( ) throws Exception { } private static int encodeValueLenient ( double x ) { } private static class ExplainingVisitor implements IntersectVisitor { final GeoShape shape ; final GeoPoint targetDocPoint ; final GeoPoint scaledDocPoint ; final IntersectVisitor in ; final List < TestGeo3DPoint . ExplainingVisitor . Cell > stack = new ArrayList < > ( ) ; private List < TestGeo3DPoint . ExplainingVisitor . Cell > stackToTargetDoc ; final int targetDocID ; final int numDims ; final int bytesPerDim ; private int targetStackUpto ; final StringBuilder b ; boolean firstPhase = true ; public ExplainingVisitor ( GeoShape shape , GeoPoint targetDocPoint , GeoPoint scaledDocPoint , IntersectVisitor in , int targetDocID , int numDims , int bytesPerDim , StringBuilder b ) { } public void startSecondPhase ( ) { } @ Override public void visit ( int docID ) throws IOException { } @ Override public void visit ( int docID , byte [ ] packedValue ) throws IOException { } @ Override public Relation compare ( byte [ ] minPackedValue , byte [ ] maxPackedValue ) { TestGeo3DPoint . ExplainingVisitor . Cell cell = new TestGeo3DPoint . ExplainingVisitor . Cell ( minPackedValue , maxPackedValue ) ; if ( firstPhase ) { <START_BUG> while ( ( ( stack . size ( ) ) > 0 ) && ( stack . get ( ( ( stack . size ( ) ) - 1 ) ) . contains ( cell ) ) ) { <END_BUG> stack . remove ( ( ( stack . size ( ) ) - 1 ) ) ; } stack . add ( cell ) ; return Relation . CELL_CROSSES_QUERY ; } else { Relation result = in . compare ( minPackedValue , maxPackedValue ) ; if ( ( ( targetStackUpto ) < ( stackToTargetDoc . size ( ) ) ) && ( cell . equals ( stackToTargetDoc . get ( targetStackUpto ) ) ) ) { b . append ( ( ( ( "<seq2seq4repair_space>on<seq2seq4repair_space>cell<seq2seq4repair_space>" + ( stackToTargetDoc . get ( targetStackUpto ) ) ) + ",<seq2seq4repair_space>wrapped<seq2seq4repair_space>visitor<seq2seq4repair_space>returned<seq2seq4repair_space>" ) + result ) ) ; ( targetStackUpto ) ++ ; } return result ; } } private class Cell { private final byte [ ] minPackedValue ; private final byte [ ] maxPackedValue ; public Cell ( byte [ ] minPackedValue , byte [ ] maxPackedValue ) { } public boolean contains ( TestGeo3DPoint . ExplainingVisitor . Cell other ) { } @ Override public String toString ( ) { } @ Override public boolean equals ( Object other ) { } @ Override public int hashCode ( ) { } } } public static String explain ( String fieldName , GeoShape shape , GeoPoint targetDocPoint , GeoPoint scaledDocPoint , IndexReader reader , int docID ) throws Exception { } }

Fix:
while ( ( ( stack . size ( ) ) > 0 ) && ( ( stack . get ( ( ( stack . size ( ) ) - 1 ) ) . contains ( cell ) ) == false ) ) {