Fix NPE if there's no query in the URI (#11836)

Change-Id: I8960e5917ffb0988e705599d1fe5e8aacf2654ef