Skip to content

Replace deprecated new URL() with URI-based parsing in Absolute.uri(String)#54

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/refactor-absolute-uri-method
Draft

Replace deprecated new URL() with URI-based parsing in Absolute.uri(String)#54
Copilot wants to merge 2 commits intomasterfrom
copilot/refactor-absolute-uri-method

Conversation

Copy link
Contributor

Copilot AI commented Feb 20, 2026

new URL(String) is deprecated since Java 20. It was used solely as a lenient parser to decompose URI strings into components for re-encoding.

Changes

  • Replace new URL(preprocessed)new URI(preprocessed) for component extraction
  • Use URI.getPath() (already decoded) instead of URLDecoder.decode(url.getPath())
  • Map getters: getProtocol()getScheme(), getRef()getFragment()
  • Pre-encode [, ], ^ before parsing — URI is stricter than URL about these in paths
  • Retain parsedUri.toURL() as a scheme validator — unknown schemes (gitlens, git, untitled) throw MalformedURLException, preserving the existing fallback to uri(URI)
  • Drop unused imports: URL, URLDecoder, StandardCharsets
// Before
var url = new URL(uri.replace("+", "%2B").replace("%%", "%25%"));
var decodedPath = URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8);
var decodedUri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), ...);

// After
var parsedUri = new URI(preprocessed);
parsedUri.toURL(); // validates known scheme, throws for unknown
var decodedPath = parsedUri.getPath();
var decodedUri = new URI(parsedUri.getScheme(), parsedUri.getUserInfo(), parsedUri.getHost(), ...);

Character-by-character comparison of toString(), getPath(), and all URI components across all 12 string-input test cases confirms identical output between old and new implementations.

Original prompt

This section details on the original issue you should resolve

<issue_title>Переписать метод Absolute.uri(string)</issue_title>
<issue_description>Конструктор new URL() деприкейт, необходимо переписать метод, избавившись от его использования</issue_description>

<agent_instructions>URL использовался как encoder. Надо понять, на что его можно заменить. </agent_instructions>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

….uri(String)

- Use new URI(preprocessed) instead of new URL(preprocessed) for parsing
- Use URI.toURL() for scheme validation (maintains fallback for unknown protocols)
- Use URI.getPath() (decoded) instead of URLDecoder.decode(url.getPath())
- Pre-encode [, ], ^ chars that URI is strict about
- Remove unused imports: java.net.URL, URLDecoder, StandardCharsets

Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
@sonarqubecloud
Copy link

Copilot AI changed the title [WIP] Refactor Absolute.uri method to remove deprecated URL constructor Replace deprecated new URL() constructor with URI-based parsing in Absolute.uri(String) Feb 20, 2026
Copilot AI requested a review from nixel2007 February 20, 2026 10:03
Copilot AI changed the title Replace deprecated new URL() constructor with URI-based parsing in Absolute.uri(String) Replace deprecated new URL() with URI-based parsing in Absolute.uri(String) Feb 20, 2026
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.

Переписать метод Absolute.uri(string)

2 participants