Fix NPE when creating a new query

Change-Id: I7ceb52759d4b4482b7d6a62617d58ccf6bfa0acc