Made sure match_all query is used in validate query when no query is specified and fixed NPE

Closes #6111