On Tue, 1 Dec 2026 15:24:01 GMT, Daniel Fuchs <[email protected]> wrote:
>> Please find here a fix that improves URL and URI normalization algorithm. >> The patch introduces a new static package-private normalize method in >> java.net.URI that both URL and URI can share. The new method is based on the >> pre-existing URI normalization algorithm, but avoids multiple backtacking >> passes in the presence of .. segments. >> >> This is globally similar to what was done for Path in >> https://github.com/openjdk/jdk/pull/33799 >> >> When applying normalization, `URLStreamHandler` now uses the shared method >> instead of rolling up its own. >> The `jar:` `Handler` now also uses the new method to normalize the resource >> path (after the bang `!` separator) >> >> URI normalization output remained unchanged, but this patch revealed a few >> corner case bugs in the existing URL normalization which can be observed and >> have been fixed along. A system property >> `jdk.net.urlDisableNormalizationOptimization=true|false` is introduced to >> revert to the old behaviour. >> A CSR will be logged to cover the addition of this new system property. >> >> I also have added a micro-benchmark for both URL and URI, taking inspiration >> from the micro-benchmark in https://github.com/openjdk/jdk/pull/33799. I >> have pasted the [results in a >> comment](https://github.com/openjdk/jdk/pull/33898#issuecomment-6922625690) >> in this PR. >> >> --------- >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > Daniel Fuchs has updated the pull request incrementally with one additional > commit since the last revision: > > Reduce formatting noise Do we need to clone some of the tests to `test/jdk/java/net/URL/Constructor.java` too? src/java.base/share/classes/java/net/URL.java line 1: > 1: /* Copyright year needs a bump. src/java.base/share/classes/jdk/internal/access/JavaNetURLAccess.java line 2: > 1: /* > 2: * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights > reserved. Suggestion: * Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved. src/java.base/share/classes/sun/net/www/protocol/jar/Handler.java line 2: > 1: /* > 2: * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights > reserved. Suggestion: * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved. test/jdk/java/net/URI/Test.java line 1: > 1: /* Could we extend the (preferably all) tests for `...` cases? For instance, foo/.../bar/.. foo/../... foo/.../../bar ... .../ .../.. You will see there surface some wrinkles when these inputs are passed. test/jdk/java/net/URI/Test.java line 1152: > 1150: .norm().p("./b:c").z(); > 1151: test("a//../b").p("a//../b") > 1152: .norm().p("b").z(); Can we extend these mixed dot and empty segment cases? For instance, a/./b/./c/../../.. a/../b/../c a/..//b/.//.. My point is, `URI::removeDots` is has extended the meaning of `segs` for improved segment removal. We should stress it sufficiently, IMHO. ------------- PR Review: https://git.openjdk.org/jdk/pull/33898#pullrequestreview-5956298170 PR Review Comment: https://git.openjdk.org/jdk/pull/33898#discussion_r4719963300 PR Review Comment: https://git.openjdk.org/jdk/pull/33898#discussion_r4719966349 PR Review Comment: https://git.openjdk.org/jdk/pull/33898#discussion_r4719968888 PR Review Comment: https://git.openjdk.org/jdk/pull/33898#discussion_r4720240182 PR Review Comment: https://git.openjdk.org/jdk/pull/33898#discussion_r4720292269
