Replace deprecated new URL constructors - #26051
Conversation
Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…t, webservices, deployment Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…xtras Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…rtial) Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…e tests Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…tClient (partial) Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…tClients Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… and remaining clients Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… (batch 1) Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… (batch 2) Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… (batch 3) Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… (batch 4) Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… (batch 5) Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… (batch 6) Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…3.1 devtests Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… (batch 7) Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…(more batches) Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… (batch 8) Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… (batch 9) Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… (batch 10) Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… (batch 11) Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… (batch 12) Refs eclipse-ee4j#25625 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…bintegration Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ersistence/security/transaction devtests Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…tor/deployment devtests Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…/webservice devtests Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…, and v2-tests Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This comment was marked as resolved.
This comment was marked as resolved.
Hi, @pzygielo! Thanks for the reply. I would like to clarify: should I add\change License info in all changed files too? |
Inline new URL(...) call sites were replaced with URI.create(...).toURL(), leaving java.net.URL unreferenced in these files. Fixes Checkstyle UnusedImports errors reported by CI. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| redirectPort = Integer.parseInt((hostAndPort.get(1))); | ||
| try { | ||
| url = new URL(protocol, serverHost, redirectPort, file.toString()); | ||
| url = new URI(protocol + "://" + serverHost + ":" + redirectPort + file).toURL(); |
There was a problem hiding this comment.
Are you sure there should not be a slash before the file? (I am not but I can be wrong!)
If I would work on this, I would do that in smaller steps - the replacement is not always 1:1 as string URL can be in several formats/encodings, with escaped or unescaped unicode characters, etc.
Now you can have even unicode in the host name and while original code might or might not be correct, these changes might or might not change it.
Maybe would be worth to try to collect some usages and try to compare them in some trivial unit test, if it does still the same, and learn traps waiting unexpected.
There was a problem hiding this comment.
Thanks, these were good catches. I checked each point against the deprecated constructor on JDK 21 and added UrlToUriConversionEquivalenceTest to pin the results down.
The slash: in RealmAdapter, file is getRequestURI() (plus an optional ;jsessionid and ?query), which per the Servlet spec always starts with /. The deprecated new URL(protocol, host, port, file) used that same string verbatim, so the slash behavior is unchanged.
Encoding / unicode — you're right, it's not a blind 1:1 swap. Comparing the two replacement forms this PR uses against the old constructor:
| input | old new URL(p,h,port,file) |
new URI(p,null,h,port,path,…) (WebServiceEndpoint) |
new URI(spec) (RealmAdapter) |
|---|---|---|---|
| ASCII path | baseline | same | same |
default port -1 |
omits :port |
same | – |
| raw unicode in path | verbatim | same | same |
pre-encoded %2F |
verbatim | %252F (double-encoded) |
same |
| raw space | verbatim | %20 |
throws |
| unicode/IDN host | verbatim | throws | same |
So concretely:
- The multi-arg form (
WebServiceEndpoint) re-encodes the path and rejects IDN hostnames the old ctor accepted — but it correctly omits a-1port, which is why I kept it there. The query-mangling is also why I did not use it inRealmAdapter. - The spec form (
RealmAdapter) preserves the host and the already-encoded request URI 1:1, but is strict about raw spaces. In practice the input is the container-encodedgetRequestURI()/getQueryString(), and the surrounding catch turns any failure into an HTTP 500 rather than a crash — so the exposure is contained, but it is a change.
None of the divergent cases are crashes; the inputs that trigger them (raw spaces, IDN hosts) don't occur on these code paths in practice, and the test documents the boundaries.
Separately, I pushed the Checkstyle UnusedImports fixes (4 files) — full reactor checkstyle is green locally now (374 modules, 0 violations).
On smaller steps: agreed in principle. The bulk of this PR is ~700 mechanical (new URL(x)).openConnection() → URI.create(x).toURL() test-file swaps; only RealmAdapter and WebServiceEndpoint carry the semantics above. Happy to peel those two into a separate, focused PR if you'd prefer to review them on their own.
There was a problem hiding this comment.
Follow-up: your "not 1:1" concern just caught a real one. The Windows CI run failed (macOS/Linux passed) in WebappClassLoader.addRepository:
java.lang.IllegalArgumentException: Invalid repository: file:/C:\Users\RUNNER~1\...\__default-web-module\
at org.glassfish.web.loader.WebappClassLoader.addRepository(WebappClassLoader.java:372)
The conversion there was new URL(repository) → URI.create(repository).toURL(). The deprecated URL(String) constructor silently normalized \ → / for file: URLs, whereas URI.create is RFC-3986 strict and rejects the native Windows separators — so web-app deployment broke on Windows only (3 StartupITest failures), exactly the platform-dependent encoding trap you described.
Fixed by reproducing the old normalization before parsing (verified on JDK 21 to be byte-identical to the old constructor for the failing input, and a no-op on / platforms):
super.addURL(URI.create(repository.replace('\\', '/')).toURL());Pushed. So +1 to splitting the semantically-loaded sites out for closer review — I've gone through the production conversions and flagged the remaining file/SSP-derived ones to watch. Thanks for pushing on this.
There was a problem hiding this comment.
I remember in the past Internet Explorer was sending absolute file paths for file inputs, while other browsers sent just the file name. This is not the case, just some random thought.
Don't separate PRs, every PR must be correct. Individual commits in the PR may "react" to each other. It is nearly the same effort to review individual commits and PRs, so I don't see a reason to split them. Also consider the CI load, which is often above limits.
… test Follow-up to the deprecated new URL() migration: - Remove now-unused java.net.URL imports left after the URI migration in ComponentEnvManagerImpl and URLObjectFactory (Checkstyle UnusedImports). - ModuleContentLinker.accept(): widen the WSDL-URL catch to (IllegalArgumentException | MalformedURLException) so a malformed http WSDL URI is still reported as "invalidWsdlURL" rather than falling through to the generic mapping-error handler now that URI.create throws an unchecked IllegalArgumentException. - Add UrlToUriConversionEquivalenceTest pinning the behaviour of the multi-argument URI replacement used in WebServiceEndpoint against the deprecated URL(protocol,host,port,file) constructor, including the default-port and pre-encoded-path boundaries. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Found by running the full reactor checkstyle locally with -Dcheckstyle.failOnViolation=false (so no downstream modules are skipped): - CatalinaProperties.java (web-core) - ConnectionUtils.java (tests/admin) In both the only remaining "URL" tokens were inside Javadoc/block comments, so an earlier text scan missed them. Full checkstyle now passes: 374 modules, 0 skipped, 0 violations. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Covers the cases dmatej raised on the PR, for both replacement forms: - multi-arg new URI(scheme,null,host,port,path,...) used by WebServiceEndpoint - spec-string new URI(scheme://host:port + file) used by RealmAdapter SSL redirect Verified on JDK 21 (surefire: 7 tests, 0 failures): - plain ASCII paths, default port (-1) and raw unicode in path: all forms match the deprecated URL(scheme,host,port,file) ctor - multi-arg form re-encodes the path (pre-encoded %2F -> %252F, raw space -> %20) and REJECTS a non-ASCII/IDN host that the old ctor accepted - spec form preserves host and pre-encoded path verbatim but is strict about raw spaces (throws); in RealmAdapter the input is already container-encoded and the failure is caught as HTTP 500 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…in file: URLs
The deprecated URL(String) constructor normalized backslashes to '/' for file:
URLs; URI.create is strict and threw IllegalArgumentException on the native
Windows separators in the generated __default-web-module repository, breaking
web app deployment (StartupITest, 3 failures on the Windows CI job; macOS/Linux
unaffected because they use '/').
Reproduce the old normalization with repository.replace('\','/') before
URI.create (no-op on '/' platforms). Verified on JDK 21 that this yields output
identical to the deprecated constructor for the failing input.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@pzygielo Do I need to add to license block info about contibuting in edited files? (year and Eclipse). If so i need to instruct Claude for that. |
We usually add over the inherited Oracle (c) line, like in top level pom: Lines 3 to 6 in 7bf4d70 As the year not longer needs to be range or even updated (https://www.eclipse.org/projects/handbook/#legaldoc-faq) - the 2026 should be fine. |
|
And handbook also has chapter https://www.eclipse.org/projects/handbook/#ai for consideration. |
This comment was marked as resolved.
This comment was marked as resolved.
The src/main changes (RealmAdapter, WebServiceEndpoint, WebappClassLoader, web-core, webservices, nucleus, ...) and the UrlToUriConversionEquivalenceTest carry non-trivial encoding/IDN/query semantics and are split out for focused review. This PR now contains only the mechanical test-code migration. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
These appserv-tests devtests are compiled by the Jenkins build but not by the Maven reactor, so the missing import slipped past the GitHub Actions build and broke the cdi-all / webservice_all Jenkins stages (cannot find symbol: variable URI). Import inserted in alphabetical order within the existing java.net import group. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adds "Copyright (c) 2026 Contributors to the Eclipse Foundation." above the existing copyright line in every file touched by this PR that did not already credit the Eclipse Foundation, per project licensing convention. Files that already carried an EF copyright line are left unchanged (the year need not be updated). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@pzygielo @dmatej — restructured this PR based on the feedback: Jenkins compile failures ( Smaller steps (@dmatej). Agreed — this PR is now test code only (the bulk mechanical License headers (@pzygielo). Added |
|
@pzygielo As those changes are just in tests, I believe we could squash and merge, what do you think? |
I do agree. One commit should do, esp. to make 'Remove accidentally committed .*', 'Move production-code URL constructor conversions to a separate PR' etc. disappear. |

Part of #25625
Replaces deprecated string-based
java.net.URLconstructors (deprecated since Java 20) withURI-based equivalents — most commonly:new URL(String spec)→URI.create(spec).toURL()(new URL(x)).openConnection()→URI.create(x).toURL().openConnection()Scope: test code only. The production (
src/main) conversions —RealmAdapter,WebServiceEndpoint,WebappClassLoader, web-core, webservices, nucleus, etc. — carry non-trivial encoding/IDN/query semantics and have been split into a separate, focused PR (withUrlToUriConversionEquivalenceTestdocumenting the divergences). This PR is now the bulk mechanical test-code migration.Also in this PR:
import java.net.URI;in 41appserv-testsdevtests files. These are compiled by Jenkins but not by the Maven reactor, so the missing import passed GitHub Actions but broke thecdi-all/webservice_allJenkins stages (cannot find symbol: variable URI).Copyright (c) 2026 Contributors to the Eclipse Foundation.to touched files that did not already credit the Eclipse Foundation.Occurrences inside comments and generated
target/artifacts are intentionally left untouched.🤖 Generated with Claude Code