BZ-1019708: fixing NPE on queries with no results
(cherry picked from commit 315cc8f4b828b43f132c15810c2500338f656321)