android icon indicating copy to clipboard operation
android copied to clipboard

Replaced own walkFileTree with correct implementation from nnio package.

Open Bensikrac opened this issue 1 year ago • 0 comments

This is another fix for that nullpointer issue as in #12476 (#12467) Apparently there was a custom implementation of the same walkFileTree-function inside of the code, suprise still had the bug. The new function, as per nnio lib is Files.java which contains the null checks:

public static Path walkFileTree(Path start, FileVisitor<? super Path> visitor) throws IOException {
    File file = start.toFile();
    if (!file.canRead()) {
      visitor.visitFileFailed(start, new AccessDeniedException(file.toString()));
      return start;
    }
    if (Files.isDirectory(start)) {
      visitor.preVisitDirectory(start, null);
      File[] children = start.toFile().listFiles();
      if (children != null) {
        for (File child : children) {
          walkFileTree(FileBasedPathImpl.get(child), visitor);
        }
        visitor.postVisitDirectory(start, null);
      }
    } else {
      visitor.visitFile(start, new BasicFileAttributes(file));
    }
    return start;
  }

instead of the one in the file.

Functionally nothing should change, since visitFileFailed gets modified, that it continues no matter what, which is the only real change in the function.

This also somehow slipped by, because the dev build 20240209 worked only with the nnio version update for some reason. Got reason: #12323 added back the broken code without the null check (caused by nnio lib 0.3 not being spec by ignoring not getting FileVisitResult.CONTINUE and therefore needing to modify the loop function (this is fixed in nnio 0.3.1) Here are the changes in nnio 0.3.1: #5

Also here is a stack trace of the issue:

05-02 01:12:25.531 25980 26045 D FileSyncHelper: File-sync start check folder /storage/emulated/0
05-02 01:12:25.540 25980 25980 I WM-SystemFgDispatcher: Started foreground service Intent { act=ACTION_START_FOREGROUND cmp=com.nextcloud.client/androidx.work.impl.foreground.SystemForegroundService (has extras) }
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper: Work [ id=b0e6b726-2807-4ed6-9fdb-920bba5be2a9, tags={ com.nextcloud.client.jobs.FilesSyncWork, *, name:periodic_files_sync, timestamp:1714604245289, class:FilesSyncWork } ] failed because it threw an exception/error
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper: java.util.concurrent.ExecutionException: java.lang.NullPointerException: Attempt to get length of null array
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at androidx.work.impl.utils.futures.AbstractFuture.getDoneValue(AbstractFuture.java:515)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at androidx.work.impl.utils.futures.AbstractFuture.get(AbstractFuture.java:474)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at androidx.work.impl.WorkerWrapper$2.run(WorkerWrapper.java:316)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at androidx.work.impl.utils.SerialExecutorImpl$Task.run(SerialExecutorImpl.java:96)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at java.lang.Thread.run(Thread.java:1012)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper: Caused by: java.lang.NullPointerException: Attempt to get length of null array
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at com.owncloud.android.utils.FileUtil.walkFileTree(FileUtil.java:76)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at com.owncloud.android.utils.FileUtil.walkFileTree(FileUtil.java:77)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at com.owncloud.android.utils.FileUtil.walkFileTree(FileUtil.java:77)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at com.owncloud.android.utils.FilesSyncHelper.insertCustomFolderIntoDB(FilesSyncHelper.java:66)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at com.owncloud.android.utils.FilesSyncHelper.insertAllDBEntriesForSyncedFolder(FilesSyncHelper.java:141)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at com.owncloud.android.utils.FilesSyncHelper.insertAllDBEntries(FilesSyncHelper.java:151)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at com.nextcloud.client.jobs.FilesSyncWork.collectChangedFiles(FilesSyncWork.kt:160)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at com.nextcloud.client.jobs.FilesSyncWork.doWork(FilesSyncWork.kt:118)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      at androidx.work.Worker$1.run(Worker.java:82)
05-02 01:12:25.547 25980 26000 E WM-WorkerWrapper:      ... 3 more
05-02 01:12:25.548 25980 26000 I WM-WorkerWrapper: Worker result FAILURE for Work [ id=b0e6b726-2807-4ed6-9fdb-920bba5be2a9, tags={ com.nextcloud.client.jobs.FilesSyncWork, *, name:periodic_files_sync, timestamp:1714604245289, class:FilesSyncWork } ]
  • [X] Tests written, or not not needed

Bensikrac avatar May 02 '24 00:05 Bensikrac