private void executeInvalidQueryWithLike(boolean useBindParam) throws Exception {
    Cache cache = CacheUtils.getCache();
    AttributesFactory attributesFactory = new AttributesFactory();
    RegionAttributes regionAttributes = attributesFactory.create();

    Region region = cache.createRegion("pos", regionAttributes);
    for (int i = 0; i < 10; i++) {
      region.put("key-" + i, new Portfolio(i));
    }
    region.put("key-" + 11, new PortfolioModifiedStatus(11));
    QueryService qs = cache.getQueryService();

    String predicate = "";
    String predicate2 = "";
    if (useBindParam) {
      predicate = "$1";
      predicate2 = "$1";
    } else {
      predicate = " '%nactive'";
      predicate2 = " 'inactive'";
    }

    Query[] q = new Query[4];
    q[0] = qs.newQuery(
        "SELECT distinct *  FROM " + SEPARATOR + "pos ps WHERE ps.status like " + predicate);
    q[1] = qs.newQuery(
        "SELECT distinct *  FROM " + SEPARATOR + "pos ps WHERE ps.status = " + predicate2);
    q[2] =
        qs.newQuery("SELECT distinct *  FROM " + SEPARATOR + "pos ps WHERE NOT (ps.status like "
            + predicate + ")");
    q[3] =
        qs.newQuery("SELECT distinct *  FROM " + SEPARATOR + "pos ps WHERE NOT (ps.status = "
            + predicate2 + ")");
    SelectResults[][] results = new SelectResults[2][2];
    if (useBindParam) {
      results[0][0] = (SelectResults) q[0].execute(new Object[] {"%nactive"});
      results[0][1] = (SelectResults) q[1].execute(new Object[] {"inactive"});
      results[1][0] = (SelectResults) q[2].execute(new Object[] {"%nactive"});
      results[1][1] = (SelectResults) q[3].execute(new Object[] {"inactive"});
    } else {
      results[0][0] = (SelectResults) q[0].execute();
      results[0][1] = (SelectResults) q[1].execute();
      results[1][0] = (SelectResults) q[2].execute();
      results[1][1] = (SelectResults) q[3].execute();
    }
    assertTrue(results[0][0].size() > 0);
    assertTrue(CacheUtils.compareResultsOfWithAndWithoutIndex(results));

    qs.createIndex("IDindex", "ps.ID", SEPARATOR + "pos ps");

    if (useBindParam) {
      results[0][0] = (SelectResults) q[0].execute(new Object[] {"%nactive"});
      results[0][1] = (SelectResults) q[1].execute(new Object[] {"inactive"});
      results[1][0] = (SelectResults) q[2].execute(new Object[] {"%nactive"});
      results[1][1] = (SelectResults) q[3].execute(new Object[] {"inactive"});
    } else {
      results[0][0] = (SelectResults) q[0].execute();
      results[0][1] = (SelectResults) q[1].execute();
      results[1][0] = (SelectResults) q[2].execute();
      results[1][1] = (SelectResults) q[3].execute();
    }
    assertTrue(results[0][0].size() > 0);
    assertTrue(CacheUtils.compareResultsOfWithAndWithoutIndex(results));
  }
Test to verify that query executes using index even when the index is being removed during the
execution
geode-core/src/integrationTest/java/org/apache/geode/cache/query/functional/LikePredicateJUnitTest.java