Skip to content

[core] Do not use path.toUri().toString() when a location string is expected internally - #7098

Merged
JingsongLi merged 1 commit into
apache:masterfrom
Zouxxyy:dev/delete-touri-tostring1
Jan 22, 2026
Merged

JingsongLi merged 1 commit into
apache:masterfrom
Zouxxyy:dev/delete-touri-tostring1

Conversation

@Zouxxyy

@Zouxxyy Zouxxyy commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

Purpose

path.toUri() converts a path into a standardized URI string (e.g., file:/tmp/path/test file → file:/tmp/path/test%20file), with special characters encoded (like spaces → %20).

we should avoid use new Path(p1.toUri().toString()), see this test

String location = "file:/tmp/path/test file";
String encodedLocation = "file:/tmp/path/test%20file";
Path p1 = new Path(location);
assertThat(p1.toString()).isEqualTo(location);
assertThat(p1.toUri().toString()).isEqualTo(encodedLocation);

// Using p1.toString() to create a new Path is correct
Path p2 = new Path(p1.toString());
assertThat(p2.toString()).isEqualTo(location);
assertThat(p2.toUri().toString()).isEqualTo(encodedLocation);

// Using p1.toUri().toString to create a new Path will encode again
Path p3 = new Path(p1.toUri().toString());
assertThat(p3.toString()).isEqualTo(encodedLocation);
assertThat(p3.toUri().toString()).isEqualTo("file:/tmp/path/test%2520file");

Tests

API and Format

Documentation

@Zouxxyy
Zouxxyy force-pushed the dev/delete-touri-tostring1 branch from 064b3f9 to 2abcafc Compare January 22, 2026 02:22

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1

@JingsongLi
JingsongLi merged commit b249c84 into apache:master Jan 22, 2026
13 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