### Question:
TwigQuery extends NodeQuery { @Override public Query rewrite(final IndexReader reader) throws IOException { if (clauses.size() == 0) { NodeQuery query = (NodeQuery) root.rewrite(reader); if (this.getBoost() != 1.0f) { if (query == root) { query = (NodeQuery) query.clone(); } query.setBoost(this.getBoost() * query.getBoost()); } query.setAncestorPointer(ancestor); return query; } if (root instanceof EmptyRootQuery && clauses.size() == 1) { NodeQuery query = (NodeQuery) clauses.get(0).getQuery().rewrite(reader); if (query == clauses.get(0).getQuery()) { query = (NodeQuery) query.clone(); } if (query instanceof AncestorFilterQuery) { final AncestorFilterQuery tmp = (AncestorFilterQuery) query; if (tmp.getBoost() != 1.0f && tmp.lowerBound != -1 && tmp.upperBound != 1) { query = ((AncestorFilterQuery) query).getQuery(); } } query = new AncestorFilterQuery(query, levelConstraint); query.setAncestorPointer(ancestor); query.setNodeConstraint(lowerBound, upperBound); if (this.getBoost() != 1.0f) { query.setBoost(this.getBoost()); } ((AncestorFilterQuery) query).getQuery().setAncestorPointer(query); return query; } if (root instanceof TwigQuery) { final TwigQuery clone = (TwigQuery) this.clone(); clone.clauses.addAll(((TwigQuery) clone.root).clauses); clone.root = ((TwigQuery) clone.root).getRoot(); for (final NodeBooleanClause clause : clone.clauses) { clause.getQuery().setAncestorPointer(clone.root); } clone.setAncestorPointer(ancestor); return clone.rewrite(reader); } TwigQuery clone = null; clone = this.rewriteRoot(clone, reader); clone = this.rewriteClauses(clone, reader); if (clone != null) { clone.setAncestorPointer(ancestor); return clone; } else { return this; } } TwigQuery(final int rootLevel);  TwigQuery(); static int getMaxClauseCount(); static void setMaxClauseCount(final int maxClauseCount); void addRoot(final NodeQuery root); void addChild(final NodeQuery query, final NodeBooleanClause.Occur occur); void addDescendant(final int nodeLevel, final NodeQuery query,
                            final NodeBooleanClause.Occur occur); @Override void setAncestorPointer(final NodeQuery ancestor); @Override void setNodeConstraint(final int lowerBound, final int upperBound); @Override void setLevelConstraint(final int levelConstraint); NodeQuery getRoot(); NodeBooleanClause[] getClauses(); List<NodeBooleanClause> clauses(); final Iterator<NodeBooleanClause> iterator(); @Override Weight createWeight(final IndexSearcher searcher); @Override Query rewrite(final IndexReader reader); @Override void extractTerms(final Set<Term> terms); @Override @SuppressWarnings("unchecked") Query clone(); @Override String toString(final String field); @Override boolean equals(final Object o); @Override int hashCode();  }### Answer:
@Test public void testRewriteEmptyRoot2() throws IOException { final TwigQuery tq = new TwigQuery(2); final NodeQuery q = (NodeQuery) tq.rewrite(null); assertTrue(q instanceof EmptyRootQuery); }