Fix possible NullPointerException and ArrayIndexOutOfBoundsException.

Wouldn't this cause a `NullPointerException` when `values` is null or an `ArrayIndexOutOfBoundsException` when the length of `values` is zero?

Suggestion: move it in the `else if` clause.