Skip to content

Comments

optimize: fix listfiles NPE#726

Open
slievrly wants to merge 1 commit intoapache:masterfrom
slievrly:master_26_02_17
Open

optimize: fix listfiles NPE#726
slievrly wants to merge 1 commit intoapache:masterfrom
slievrly:master_26_02_17

Conversation

@slievrly
Copy link
Member

Ⅰ. Describe what this PR did

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

Signed-off-by: slievrly <slievrly@163.com>
Copilot AI review requested due to automatic review settings February 16, 2026 16:30
@slievrly slievrly changed the title fix listfiles NPE optimize: fix listfiles NPE Feb 16, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Prevents a null-pointer failure in the e2e test runner when the configured e2e directory cannot be listed (e.g., missing, not a directory, or inaccessible).

Changes:

  • Add a null-check for File.listFiles() results in SkyWalkingController.runE2ETests().
  • Log an error and exit early when directory listing fails.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +61 to +62
LOGGER.error("Failed to list files in directory: " + this.e2eDir);
LOGGER.error("Please check if the directory exists and is accessible.");
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

These new log lines use string concatenation; elsewhere in this file SLF4J parameterized logging is used (e.g., LOGGER.error("Test Directory: {}", ...)). Prefer {} placeholders here as well to avoid unnecessary string building and keep logging consistent.

Copilot uses AI. Check for mistakes.
Comment on lines 57 to 59
File e2eDir = new File(this.e2eDir);
List<String> passedProjects = new ArrayList<>();
File[] files = e2eDir.listFiles();
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

The local variable File e2eDir = new File(this.e2eDir); shadows the e2eDir field name; with the added error handling it’s now easy to confuse this.e2eDir (String) vs e2eDir (File). Renaming the local variable (e.g., e2eDirFile) would make this block clearer.

Suggested change
File e2eDir = new File(this.e2eDir);
List<String> passedProjects = new ArrayList<>();
File[] files = e2eDir.listFiles();
File e2eDirFile = new File(this.e2eDir);
List<String> passedProjects = new ArrayList<>();
File[] files = e2eDirFile.listFiles();

Copilot uses AI. Check for mistakes.
Comment on lines 59 to +62
File[] files = e2eDir.listFiles();
if (files == null) {
LOGGER.error("Failed to list files in directory: " + this.e2eDir);
LOGGER.error("Please check if the directory exists and is accessible.");
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

File.listFiles() returns null for multiple reasons (path doesn’t exist, not a directory, I/O/permission issues). Consider checking e2eDir.exists() / e2eDir.isDirectory() and logging the absolute path + those flags so failures are easier to diagnose.

Copilot uses AI. Check for mistakes.
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.

1 participant