Skip to content

fix AccessDeniedException при чтении#625

Merged
theshadowco merged 1 commit into
developfrom
feature/fixAccessDeniedException
Jun 29, 2026
Merged

fix AccessDeniedException при чтении#625
theshadowco merged 1 commit into
developfrom
feature/fixAccessDeniedException

Conversation

@theshadowco

@theshadowco theshadowco commented Jun 29, 2026

Copy link
Copy Markdown
Member

Описание

Исправление ошибки чтения недоступных каталогов

Связанные задачи

Closes: #609

Чеклист

Общие

  • Ветка PR обновлена из develop
  • Отладочные, закомментированные и прочие, не имеющие смысла участки кода удалены
  • Изменения покрыты тестами
  • Обязательные действия перед коммитом выполнены (запускал команду gradlew precommit)

Дополнительно

Summary by CodeRabbit

  • Bug Fixes
    • Improved file scanning so matching project files are found more reliably in nested folders.
    • Better handles unreadable directories during scanning by skipping them instead of failing the entire operation.
    • Fixed list selection logic to use the first available item consistently when only one option is present.

AccessDeniedException
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

MDClasses.findFiles is rewritten from a Files.find stream approach to Files.walkFileTree with a SimpleFileVisitor, adding graceful handling of AccessDeniedException (log warning and continue) and rethrowing other IO errors as UncheckedIOException. Two get(0) calls in createSolution are updated to getFirst().

MDClasses filesystem traversal fix

Layer / File(s) Summary
findFiles walkFileTree refactor and createSolution cleanup
src/main/java/com/github/_1c_syntax/bsl/mdclasses/MDClasses.java
Imports swap Stream for UncheckedIOException, AccessDeniedException, and FileVisitResult. findFiles replaces Files.find(...) with Files.walkFileTree(...) + SimpleFileVisitor, skipping excluded folders by parent/grandparent name, filtering by xml/mdo extension and filename pattern, warning-and-continuing on AccessDeniedException, and rethrowing other failures as UncheckedIOException. createSolution replaces get(0) with getFirst() in both single-result and fallback return paths.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hopping through the file tree wide,
When access is denied, I step aside,
No more crashes at /sys/kernel/tracing,
Just a warning logged and onward racing,
getFirst() now leads the way with grace —
A safer, tidier scanning pace! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and clearly matches the main change: handling AccessDeniedException while reading directories.
Linked Issues check ✅ Passed The PR rewrites file scanning with walkFileTree and skips AccessDeniedException, matching issue #609's expected behavior.
Out of Scope Changes check ✅ Passed The changes appear focused on the filesystem-scan fix, with no clearly unrelated code introduced.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fixAccessDeniedException

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/com/github/_1c_syntax/bsl/mdclasses/MDClasses.java`:
- Around line 292-296: The parent-name extraction in MDClasses is still unsafe
for files directly under the filesystem root because
path.getParent().getFileName() can be null and then .toString() throws. Update
the parentName handling in MDClasses to mirror the existing parentParentName
guard by checking both getParent() and getFileName() before converting to a
string, so traversal over "/" and other root-level files does not fail.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 57776c06-3a3c-4f28-8a26-a7e3f2b3b391

📥 Commits

Reviewing files that changed from the base of the PR and between 05f0294 and 35ce2ce.

📒 Files selected for processing (1)
  • src/main/java/com/github/_1c_syntax/bsl/mdclasses/MDClasses.java

Comment on lines +292 to +296
var parentName = path.getParent().getFileName().toString();
var parentParentName = "";
if (path.getParent().getParent() != null && path.getParent().getParent().getFileName() != null) {
parentParentName = path.getParent().getParent().getFileName().toString();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

NPE risk when a file resides directly under the filesystem root.

path.getParent().getFileName() returns null when the parent is a root path (e.g. /). Calling .toString() on it then throws NullPointerException. Since this PR specifically targets traversal of / and protected system paths (issue #609), a regular file located directly under / (parent /, getFileName() == null) would crash traversal — defeating the purpose of the fix. Note the grandparent computation at Line 294 already guards against a null getFileName(), but the parent at Line 292 does not.

🐛 Proposed fix to guard the parent name
-          var parentName = path.getParent().getFileName().toString();
-          var parentParentName = "";
-          if (path.getParent().getParent() != null && path.getParent().getParent().getFileName() != null) {
-            parentParentName = path.getParent().getParent().getFileName().toString();
-          }
+          var parent = path.getParent();
+          var parentName = "";
+          if (parent != null && parent.getFileName() != null) {
+            parentName = parent.getFileName().toString();
+          }
+          var parentParentName = "";
+          if (parent != null && parent.getParent() != null && parent.getParent().getFileName() != null) {
+            parentParentName = parent.getParent().getFileName().toString();
+          }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var parentName = path.getParent().getFileName().toString();
var parentParentName = "";
if (path.getParent().getParent() != null && path.getParent().getParent().getFileName() != null) {
parentParentName = path.getParent().getParent().getFileName().toString();
}
var parent = path.getParent();
var parentName = "";
if (parent != null && parent.getFileName() != null) {
parentName = parent.getFileName().toString();
}
var parentParentName = "";
if (parent != null && parent.getParent() != null && parent.getParent().getFileName() != null) {
parentParentName = parent.getParent().getFileName().toString();
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/com/github/_1c_syntax/bsl/mdclasses/MDClasses.java` around
lines 292 - 296, The parent-name extraction in MDClasses is still unsafe for
files directly under the filesystem root because path.getParent().getFileName()
can be null and then .toString() throws. Update the parentName handling in
MDClasses to mirror the existing parentParentName guard by checking both
getParent() and getFileName() before converting to a string, so traversal over
"/" and other root-level files does not fail.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
52.2% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Test Results

  402 files  ±0    402 suites  ±0   5m 17s ⏱️ -24s
  286 tests ±0    286 ✅ ±0  0 💤 ±0  0 ❌ ±0 
1 776 runs  ±0  1 776 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 35ce2ce. ± Comparison against base commit 363b1f3.

♻️ This comment has been updated with latest results.

@theshadowco theshadowco merged commit 6e0bfc7 into develop Jun 29, 2026
18 of 19 checks passed
@theshadowco theshadowco deleted the feature/fixAccessDeniedException branch June 29, 2026 08:01
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.

AccessDeniedException when scanning filesystem root due to Files.walk without error handling

1 participant