Buggy code:
public class CpRelationManager implements RelationManager { private static final Logger logger = LoggerFactory . getLogger ( CpRelationManager . class ) ; private CpEntityManagerFactory emf ; private ManagerCache managerCache ; private EntityManager em ; private UUID applicationId ; private EntityRef headEntity ; private Entity cpHeadEntity ; private ApplicationScope applicationScope ; private MetricsFactory metricsFactory ; private Timer updateCollectionTimer ; public CpRelationManager ( ) { } public CpRelationManager init ( EntityManager em , CpEntityManagerFactory emf , UUID applicationId , EntityRef headEntity , IndexBucketLocator indexBucketLocator , MetricsFactory metricsFactory ) { } @ Override public Set < String > getCollectionIndexes ( String collectionName ) throws Exception { } @ Override public Map < String , Map < UUID , Set < String > > > getOwners ( ) throws Exception { } private Map < EntityRef , Set < String > > getContainers ( ) { } Map < EntityRef , Set < String > > getContainers ( final int limit , final String edgeType , final String fromEntityType ) { } public void updateContainingCollectionAndCollectionIndexes ( final org . apache . usergrid . persistence . model . entity . Entity cpEntity ) { } @ Override public boolean isConnectionMember ( String connectionType , EntityRef entity ) throws Exception { } @ SuppressWarnings ( "unchecked" ) @ Override public boolean isCollectionMember ( String collName , EntityRef entity ) throws Exception { } private boolean moreThanOneInboundConnection ( EntityRef target , String connectionType ) { } @ Override public Set < String > getCollections ( ) throws Exception { } @ Override public Results getCollection ( String collectionName , UUID startResult , int count , Level resultsLevel , boolean reversed ) throws Exception { } @ Override public Results getCollection ( String collName , Query query , Level level ) throws Exception { } @ Override public Entity addToCollection ( String collName , EntityRef itemRef ) throws Exception { } public Entity addToCollection ( String collName , EntityRef itemRef , boolean connectBack ) throws Exception { } public Entity addToCollection ( final String collName , final EntityRef itemRef , final org . apache . usergrid . persistence . model . entity . Entity memberEntity , final boolean connectBack ) throws Exception { } @ Override public Entity addToCollections ( List < EntityRef > owners , String collName ) throws Exception { } @ Override public Entity createItemInCollection ( String collName , String itemType , Map < String , Object > properties ) throws Exception { } @ Override public void removeFromCollection ( String collName , EntityRef itemRef ) throws Exception { } @ Override public void copyRelationships ( String srcRelationName , EntityRef dstEntityRef , String dstRelationName ) throws Exception { } @ Override public Results searchCollection ( String collName , Query query ) throws Exception { } @ Override public ConnectionRef createConnection ( ConnectionRef connection ) throws Exception { } @ Override public ConnectionRef createConnection ( String connectionType , EntityRef connectedEntityRef ) throws Exception { } @ Override public ConnectionRef createConnection ( String pairedConnectionType , EntityRef pairedEntity , String connectionType , EntityRef connectedEntityRef ) throws Exception { } @ Override public ConnectionRef createConnection ( ConnectedEntityRef ... connections ) throws Exception { } @ Override public ConnectionRef connectionRef ( String connectionType , EntityRef connectedEntityRef ) throws Exception { } @ Override public ConnectionRef connectionRef ( String pairedConnectionType , EntityRef pairedEntity , String connectionType , EntityRef connectedEntityRef ) throws Exception { } @ Override public ConnectionRef connectionRef ( ConnectedEntityRef ... connections ) { } @ Override public void deleteConnection ( ConnectionRef connectionRef ) throws Exception { } @ Override public Set < String > getConnectionTypes ( UUID connectedEntityId ) throws Exception { } @ Override public Set < String > getConnectionTypes ( ) throws Exception { } @ Override public Set < String > getConnectionTypes ( boolean filterConnection ) throws Exception { } @ Override public Results getConnectedEntities ( String connectionType , String connectedEntityType , Level level ) throws Exception { } @ Override public Results getConnectingEntities ( String connType , String fromEntityType , Level resultsLevel ) throws Exception { } @ Override public Results getConnectingEntities ( String connType , String fromEntityType , Level level , int count ) throws Exception { } @ Override public Results searchConnectedEntities ( Query query ) throws Exception { } private Query adjustQuery ( Query query ) { <START_BUG> if ( ( query . getQl ( ) ) == null ) { <END_BUG> if ( query . containsSingleNameOrEmailIdentifier ( ) ) { Identifier ident = query . getSingleIdentifier ( ) ; if ( ( query . getEntityType ( ) . equals ( ENTITY_TYPE ) ) && ( ident . isEmail ( ) ) ) { final String newQuery = ( "select<seq2seq4repair_space>*<seq2seq4repair_space>where<seq2seq4repair_space>email='" + ( query . getSingleNameOrEmailIdentifier ( ) ) ) + "'" ; query . setQl ( newQuery ) ; } else { final String newQuery = ( "select<seq2seq4repair_space>*<seq2seq4repair_space>where<seq2seq4repair_space>name='" + ( query . getSingleNameOrEmailIdentifier ( ) ) ) + "'" ; query . setQl ( newQuery ) ; } } else if ( query . containsSingleUuidIdentifier ( ) ) { final String newQuery = ( "select<seq2seq4repair_space>*<seq2seq4repair_space>where<seq2seq4repair_space>uuid='" + ( query . getSingleUuidIdentifier ( ) ) ) + "'" ; query . setQl ( newQuery ) ; } } return query ; } @ Override public Set < String > getConnectionIndexes ( String connectionType ) throws Exception { } private CpRelationManager getRelationManager ( EntityRef headEntity ) { } private Entity getHeadEntity ( ) throws Exception { } }

Fix:
if ( ! ( query . getQl ( ) . isPresent ( ) ) ) {