Skip to content

Fix NRE when localpath was null#5941

Merged
premun merged 3 commits intodotnet:mainfrom
adamzip:fix-localpath-NRE
Feb 12, 2026
Merged

Fix NRE when localpath was null#5941
premun merged 3 commits intodotnet:mainfrom
adamzip:fix-localpath-NRE

Conversation

@adamzip
Copy link
Contributor

@adamzip adamzip commented Feb 11, 2026

Copilot AI review requested due to automatic review settings February 11, 2026 17:11
Copy link
Contributor

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

Updates DARC’s remote file-fetching logic to avoid a null-reference exception when the optional baseDirectory is not provided, specifically in GetCommonScriptFilesAsync.

Changes:

  • Coalesce baseDirectory to an empty path and build a single commonScriptsPath.
  • Pass the computed commonScriptsPath into _remoteGitClient.GetFilesAtCommitAsync.
  • Update logging to report the computed common scripts path.

Comment on lines +460 to +464
baseDirectory = baseDirectory ?? UnixPath.Empty;

List<GitFile> files = await _remoteGitClient.GetFilesAtCommitAsync(repoUri, commit, path);
string commonScriptsPath = baseDirectory / Constants.CommonScriptFilesPath;

List<GitFile> files = await _remoteGitClient.GetFilesAtCommitAsync(repoUri, commit, commonScriptsPath);
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

When baseDirectory is null this now becomes UnixPath.Empty, but commonScriptsPath = baseDirectory / ... uses the LocalPath / operator (compile-time type), which will combine empty left + right into a path with a leading / (e.g. /eng/common). Previously the null case used Constants.CommonScriptFilesPath (eng/common) without the leading slash. Consider preserving the old behavior (keep the conditional), or cast/convert to UnixPath before combining so UnixPath's empty-path handling is used.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

@adamzip adamzip Feb 11, 2026

Choose a reason for hiding this comment

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

    public static UnixPath operator /(UnixPath left, string right)
        => IsEmptyPath(left)
            ? new(right)
            : new(left.Combine(left.Path, left.NormalizePath(right)), false);

UnixPath.Empty combined with another path should not produce any extra slashes according to this implementation

Comment on lines 466 to 467
if (stripBaseDirectory)
{
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

The stripBaseDirectory branch below uses f.FilePath.TrimStart(baseDirectory).ToString() which does not remove a base-directory prefix; it trims any leading characters contained in baseDirectory (via MemoryExtensions.TrimStart on spans). For base directories like src/arcade, this can corrupt paths (e.g., stripping the leading e from eng/...). Consider replacing that logic with explicit prefix/path-segment removal (e.g., StartsWith baseDirectory + separator and slice/replace only that prefix).

Copilot uses AI. Check for mistakes.
@premun premun merged commit 365ae80 into dotnet:main Feb 12, 2026
3 of 8 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.

3 participants