You can get rid of the null check here and change the query.getRequiredQueryStringParam() to getQueryStringParam() since the .hasQuery.. confirms that the parameter exists.