public MetadataSyncPathList lockPath(AlluxioURI uri) throws InvalidPathException, IOException {
    MetadataSyncPathList list = new MetadataSyncPathList();
    String[] components = PathUtils.getPathComponents(uri.getPath());
    StringBuilder sb = new StringBuilder();
    // TODO(elega) potential inefficient string operations
    try {
      for (int i = 0; i < components.length; ++i) {
        sb.append(components[i]);
        sb.append(AlluxioURI.SEPARATOR);
        String lockKey = sb.toString();
        Preconditions.checkNotNull(lockKey);
        LockMode lockMode = (i == components.length - 1) ? LockMode.WRITE : LockMode.READ;
        list.add(mLockPool.get(lockKey, lockMode));
      }
    } catch (Throwable t) {
      list.close();
    }
    return list;
  }
@Test
  public void invalidPath() {
    assertThrows(InvalidPathException.class, () -> {
      try (MetadataSyncLockManager.MetadataSyncPathList ignored
               = mMetadataSyncLockManager.lockPath(new AlluxioURI("invalid path"))) {
        Void dummy;
      }
    });
    assertThrows(InvalidPathException.class, () -> {
      try (MetadataSyncLockManager.MetadataSyncPathList ignored
               = mMetadataSyncLockManager.lockPath(new AlluxioURI(" /aa/b/c "))) {
        Void dummy;
      }
    });
  }