Fix NPE in handleQueryWithUnboundKey method