code: private void checkIndices(int... indices) {
          if (indices.length != dims.length) {
              throw new IllegalArgumentException(String.format(
                      "Indices array is not the correct length. expected=%d actual=%d", 
                      indices.length, dims.length));
          }
          for (int i=0; i<indices.length; i++) {
              if (indices[i] < 0 || dims[i] <= indices[i]) {
                  throw new IllegalArgumentException(String.format(
                          "Indices array contains an index that is out of bounds: i=%d index=%d", 
                          i, indices[i]));
              }
          }
      }
docs: Checks that the indices are valid.