Skip to content

downloader: fix opaque file URI names#29549

Open
sluongng wants to merge 1 commit into
bazelbuild:masterfrom
sluongng:master
Open

downloader: fix opaque file URI names#29549
sluongng wants to merge 1 commit into
bazelbuild:masterfrom
sluongng:master

Conversation

@sluongng
Copy link
Copy Markdown
Contributor

Fix a Bazel 9.1.0 regression where repository_ctx.download
could crash on opaque file URIs such as file:../archive.tgz. The
URL-to-URI migration changed basename extraction because URI.getPath()
returns null for these inputs, unlike URL#getPath(). DownloadManager
then passed null to PathFragment.create while building distdir
candidate names.

Reuse one basename helper for download destinations and distdir
lookups, falling back to the scheme-specific part for opaque URIs.
Add regression coverage for the explicit-output and typed-download
paths.

Fixes #29393.

Fix a Bazel 9.1.0 regression where repository_ctx.download
could crash on opaque file URIs such as file:../archive.tgz. The
URL-to-URI migration changed basename extraction because URI.getPath()
returns null for these inputs, unlike URL#getPath(). DownloadManager
then passed null to PathFragment.create while building distdir
candidate names.

Reuse one basename helper for download destinations and distdir
lookups, falling back to the scheme-specific part for opaque URIs.
Add regression coverage for the explicit-output and typed-download
paths.

Fixes bazelbuild#29393.
@sluongng sluongng marked this pull request as ready for review May 15, 2026 16:33
@github-actions github-actions Bot added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. awaiting-review PR is awaiting review from an assigned reviewer labels May 15, 2026
if (path == null && url.isOpaque()) {
// Match URL#getPath() behavior for opaque file URIs such as file:../archive.tgz.
String rawPath = url.getRawSchemeSpecificPart();
if (rawPath != null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

path =
rawPath.isEmpty()
? ""
: URI.create(url.getScheme() + ":" + rawPath).getSchemeSpecificPart();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't understand this line. Isn't this just equivalent to rawPath itself? In fact aren't lines 556-559 just saying path=rawPath?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR is awaiting review from an assigned reviewer team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullPointerException in DownloadManager in 9.1.0

2 participants