Skip to content

Conversation

@DropSnorz
Copy link
Owner

@DropSnorz DropSnorz commented Oct 4, 2025

Relates to #376

@coderabbitai
Copy link

coderabbitai bot commented Oct 4, 2025

Walkthrough

Refactors FileSyncTask to support multiple directories via a new constructor, makes key fields final, improves logging, adds null/existence guards for directory listing, reuses listed subFiles in size extraction, and enhances error handling by rethrowing exceptions as TaskException while updating log phrasing.

Changes

Cohort / File(s) Summary of Changes
File sync task refactor for multi-directory and robustness
owlplug-client/src/main/java/com/owlplug/plugin/tasks/FileSyncTask.java
- Added public constructor FileSyncTask(FileStatRepository, List) to accept multiple directories
- Made fileStatRepository and directories final; directories init via Collections.singletonList for single path
- Added startup log with directory count; revised processing logs
- Added guards: skip when directory missing or listFiles returns null; reuse subFiles in extractFolderSize
- Enhanced error handling in start(): log and rethrow as TaskException
- Maintained directoryStat creation and parent linkage; adjusted phrasing like "Syncing file stats"/"Completed file stat sync"

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant Task as FileSyncTask
  participant FS as Filesystem
  participant Repo as FileStatRepository

  Caller->>Task: start()
  Note over Task: Log: starting with N directories
  loop For each directory
    Task->>FS: listFiles(dir)
    alt Directory missing or listFiles == null
      Task-->>Task: skip directory
    else Valid listing
      Task->>Task: extractFolderSize(subFiles)
      Task->>Repo: save/update directoryStat
    end
  end
  Task-->>Caller: success
  Note over Task: Log: Completed file stat sync

  rect rgba(255,224,224,0.35)
  Note over Task: Error path
  Caller->>Task: start()
  Task->>Task: catches Exception
  Task->>Caller: throws TaskException
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly indicates that the pull request addresses a null pointer exception during directory file listing in the file synchronization task, which matches the added null and existence guards and revised logging in the changeset.
Description Check ✅ Passed The description notes that this PR relates to issue #376, which aligns with the fix implemented, and is therefore on-topic and related to the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/file-stat-npe

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DropSnorz
Copy link
Owner Author

@coderabbitai review

@DropSnorz DropSnorz self-assigned this Oct 4, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 4, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
owlplug-client/src/main/java/com/owlplug/plugin/tasks/FileSyncTask.java (1)

86-94: Order of operations issue: check directory existence before deleting stats.

The current implementation deletes existing file stats from the database (line 86) and flushes (line 88) before checking if the directory exists or if listFiles() returns null (line 92). If the directory doesn't exist or an I/O error occurs, the stats are deleted but not recreated, leading to data loss.

Apply this diff to check existence before deletion:

     this.updateMessage("Collecting file metrics on directory: " + directory.getAbsolutePath());
-    fileStatRepository.deleteByPath(FileUtils.convertPath(directory.getAbsolutePath()));
-    // Flushing context to the database as next queries will recreate entities
-    fileStatRepository.flush();
-
     // files can be null in case of I/O exceptions
     File[] subFiles = directory.listFiles();
     if (!directory.exists() || subFiles == null) {
       return length;
     }
+
+    fileStatRepository.deleteByPath(FileUtils.convertPath(directory.getAbsolutePath()));
+    // Flushing context to the database as next queries will recreate entities
+    fileStatRepository.flush();
🧹 Nitpick comments (1)
owlplug-client/src/main/java/com/owlplug/plugin/tasks/FileSyncTask.java (1)

67-70: Consider logging when a directory doesn't exist.

The code silently skips non-existent directories without logging. This could make troubleshooting difficult when a configured directory path is invalid.

Consider adding a log statement:

         File directory = new File(directoryPath);
         if (directory.exists() && directory.isDirectory()) {
           length = extractFolderSize(directory, null);
           log.info("Completed file stat sync on directory {}, computed length: {}", directoryPath, length);
+        } else {
+          log.warn("Directory does not exist or is not a directory: {}", directoryPath);
         }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c16102f and 622e6c5.

📒 Files selected for processing (1)
  • owlplug-client/src/main/java/com/owlplug/plugin/tasks/FileSyncTask.java (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (6)
owlplug-client/src/main/java/com/owlplug/plugin/tasks/FileSyncTask.java (6)

38-38: LGTM! Fields properly marked as final.

Making fileStatRepository and directories final improves immutability and clearly communicates that these fields won't be reassigned after construction.

Also applies to: 40-40


44-44: Good optimization with Collections.singletonList.

Using Collections.singletonList instead of Arrays.asList is more memory-efficient for single-element lists and better expresses the intent.


48-52: LGTM! Multi-directory support added.

The new constructor properly enables processing multiple directories while maintaining the existing single-directory API.


60-60: Good logging addition.

Logging the number of directories being processed improves observability.


90-94: LGTM! Null check prevents NPE.

The null check for subFiles correctly addresses the NPE issue from #376. The listFiles() method returns null when the path doesn't denote a directory or an I/O error occurs.


107-107: Good optimization reusing subFiles.

Reusing the subFiles variable avoids calling directory.listFiles() twice, which improves performance.

@DropSnorz DropSnorz merged commit ff101fc into master Oct 4, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants