You need to check if withAnyOfTheseTypesOrOrderOfPreference is not null otherwise you will get a NullPointerException on this line