Buggy code:
public class SpatialOpRecursivePrefixTreeTest extends StrategyTestCase { static final int ITERATIONS = 10 ; private SpatialPrefixTree grid ; @ Before public void setUp ( ) throws Exception { } public void setupGrid ( int maxLevels ) throws IOException { } private void setupQuadGrid ( int maxLevels ) { } public void setupGeohashGrid ( int maxLevels ) { } @ Test @ Repeat ( iterations = SpatialOpRecursivePrefixTreeTest . ITERATIONS ) public void testIntersects ( ) throws IOException { } @ Test @ Repeat ( iterations = SpatialOpRecursivePrefixTreeTest . ITERATIONS ) public void testWithin ( ) throws IOException { } @ Test @ Repeat ( iterations = SpatialOpRecursivePrefixTreeTest . ITERATIONS ) public void testContains ( ) throws IOException { } @ Test @ Repeat ( iterations = SpatialOpRecursivePrefixTreeTest . ITERATIONS ) public void testDisjoint ( ) throws IOException { } @ Test public void testContainsPairOverlap ( ) throws IOException { } @ Test public void testWithinDisjointParts ( ) throws IOException { } @ Test public void testWithinLeafApproxRule ( ) throws IOException { } @ Override protected Document newDoc ( String id , Shape shape ) { } private void doTest ( final SpatialOperation operation ) throws IOException { { Query query = strategy . makeQuery ( new SpatialArgs ( operation , randomRectangle ( ) ) ) ; SearchResults searchResults = executeQuery ( query , 1 ) ; assertEquals ( 0 , searchResults . numFound ) ; } final boolean biasContains = operation == ( SpatialOperation . Contains ) ; Map < String , Shape > indexedShapes = new LinkedHashMap < > ( ) ; Map < String , Shape > indexedShapesGS = new LinkedHashMap < > ( ) ; final int numIndexedShapes = randomIntBetween ( 1 , 6 ) ; boolean indexedAtLeastOneShapePair = false ; for ( int i = 0 ; i < numIndexedShapes ; i ++ ) { String id = "" + i ; Shape indexedShape ; int R = random ( ) . nextInt ( 12 ) ; if ( R == 0 ) { indexedShape = null ; } else if ( R == 1 ) { indexedShape = randomPoint ( ) ; } else if ( R <= 4 ) { indexedShape = randomShapePairRect ( biasContains ) ; indexedAtLeastOneShapePair = true ; } else { indexedShape = randomRectangle ( ) ; } indexedShapes . put ( id , indexedShape ) ; indexedShapesGS . put ( id , gridSnap ( indexedShape ) ) ; adoc ( id , indexedShape ) ; if ( ( random ( ) . nextInt ( 10 ) ) == 0 ) commit ( ) ; } Iterator < String > idIter = indexedShapes . keySet ( ) . iterator ( ) ; while ( idIter . hasNext ( ) ) { String id = idIter . next ( ) ; if ( ( random ( ) . nextInt ( 10 ) ) == 0 ) { deleteDoc ( id ) ; idIter . remove ( ) ; indexedShapesGS . remove ( id ) ; } } commit ( ) ; final int numQueryShapes = atLeast ( 20 ) ; for ( int i = 0 ; i < numQueryShapes ; i ++ ) { int scanLevel = randomInt ( grid . getMaxLevels ( ) ) ; ( ( RecursivePrefixTreeStrategy ) ( strategy ) ) . setPrefixGridScanLevel ( scanLevel ) ; final Shape queryShape ; switch ( randomInt ( 10 ) ) { case 0 : queryShape = randomPoint ( ) ; break ; case 1 : case 2 : case 3 : if ( ! indexedAtLeastOneShapePair ) { <START_BUG> queryShape = randomShapePairRect ( biasContains ) ; <END_BUG> break ; } default : queryShape = randomRectangle ( ) ; } final Shape queryShapeGS = gridSnap ( queryShape ) ; final boolean opIsDisjoint = operation == ( SpatialOperation . IsDisjointTo ) ; Set < String > expectedIds = new LinkedHashSet < > ( ) ; Set < String > secondaryIds = new LinkedHashSet < > ( ) ; for ( Map . Entry < String , Shape > entry : indexedShapes . entrySet ( ) ) { String id = entry . getKey ( ) ; Shape indexedShapeCompare = entry . getValue ( ) ; if ( indexedShapeCompare == null ) continue ; Shape queryShapeCompare = queryShape ; if ( operation . evaluate ( indexedShapeCompare , queryShapeCompare ) ) { expectedIds . add ( id ) ; if ( opIsDisjoint ) { indexedShapeCompare = indexedShapesGS . get ( id ) ; queryShapeCompare = queryShapeGS ; if ( ! ( operation . evaluate ( indexedShapeCompare , queryShapeCompare ) ) ) secondaryIds . add ( id ) ; } } else if ( ! opIsDisjoint ) { if ( operation == ( SpatialOperation . Intersects ) ) { indexedShapeCompare = indexedShapesGS . get ( id ) ; queryShapeCompare = queryShapeGS ; } else if ( operation == ( SpatialOperation . Contains ) ) { indexedShapeCompare = indexedShapesGS . get ( id ) ; } else if ( operation == ( SpatialOperation . IsWithin ) ) { queryShapeCompare = queryShapeGS ; } if ( operation . evaluate ( indexedShapeCompare , queryShapeCompare ) ) secondaryIds . add ( id ) ; } } SpatialArgs args = new SpatialArgs ( operation , queryShape ) ; if ( queryShape instanceof SpatialOpRecursivePrefixTreeTest . ShapePair ) args . setDistErrPct ( 0.0 ) ; Query query = strategy . makeQuery ( args ) ; SearchResults got = executeQuery ( query , 100 ) ; Set < String > remainingExpectedIds = new LinkedHashSet < > ( expectedIds ) ; for ( SearchResult result : got . results ) { String id = result . getId ( ) ; boolean removed = remainingExpectedIds . remove ( id ) ; if ( ( ! removed ) && ( ( ! opIsDisjoint ) && ( ! ( secondaryIds . contains ( id ) ) ) ) ) { fail ( "Shouldn't<seq2seq4repair_space>match" , id , indexedShapes , indexedShapesGS , queryShape ) ; } }

Fix:
queryShape = randomShapePairRect ( ( ! biasContains ) ) ;