private static Method findRenameMethodRecursively(Class<?> clazz) throws NoSuchMethodException
  {
    try {
      Method renameMethod = clazz.getDeclaredMethod("rename", Path.class, Path.class, Options.Rename[].class);
      renameMethod.setAccessible(true);
      return renameMethod;
    }
    catch (NoSuchMethodException ex) {
      Class<?> superClazz = clazz.getSuperclass();
      if (superClazz == null) {
        throw ex;
      } else {
        return findRenameMethodRecursively(superClazz);
      }
    }
  }
private static Method findRenameMethodRecursively ( Class < ? > clazz ) throws NoSuchMethodException { try { Method renameMethod = clazz . getDeclaredMethod ( "rename" , Path . class , Path . class , Options . Rename [ ] . class ) ; renameMethod . setAccessible ( true ) ; return renameMethod ; } catch ( NoSuchMethodException ex ) { Class < ? > superClazz = clazz . getSuperclass ( ) ; if ( superClazz == null ) { throw ex ; } else { return findRenameMethodRecursively ( superClazz ) ; } } }
Finds "rename" method recursively through the FileSystem class hierarchy. This is required because
clazz.getMethod(..) only returns PUBLIC methods in clazz hierarchy.
and clazz.getDeclaredMethod(..) only returns all methods declared in clazz but not inherited ones.