private static int arrayValidLength(int[] array) {
    int len = array.length;
    while (len > 0 && array[len - 1] == 0) {
      --len;
    }
    return len <= 0 ? 0 : len;
  }
Returns length of the array discounting the trailing elements with zero value.
common/src/java/org/apache/hadoop/hive/common/type/SqlMathUtil.java