Skip to content

Replace deprecated new URL constructors - #26051

Merged
dmatej merged 47 commits into
eclipse-ee4j:mainfrom
renatsaf:replace-deprecated-url-constructors
Jul 25, 2026
Merged

Replace deprecated new URL constructors#26051
dmatej merged 47 commits into
eclipse-ee4j:mainfrom
renatsaf:replace-deprecated-url-constructors

Conversation

@renatsaf

@renatsaf renatsaf commented May 31, 2026

Copy link
Copy Markdown
Contributor

Part of #25625

Replaces deprecated string-based java.net.URL constructors (deprecated since Java 20) with URI-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 (with UrlToUriConversionEquivalenceTest documenting the divergences). This PR is now the bulk mechanical test-code migration.

Also in this PR:

  • Added the missing import java.net.URI; in 41 appserv-tests devtests files. These are compiled by Jenkins but not by the Maven reactor, so the missing import passed GitHub Actions but broke the cdi-all / webservice_all Jenkins stages (cannot find symbol: variable URI).
  • Added 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

renatsaf and others added 30 commits May 28, 2026 19:42
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>
renatsaf and others added 5 commits May 31, 2026 11:25
…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>
@pzygielo

This comment was marked as resolved.

@renatsaf

renatsaf commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author
04:53:58  [INFO] There are 2 errors reported by Checkstyle 13.4.2 with org/glassfish/qa/config/checkstyle/checkstyle.xml ruleset.

04:53:58  [ERROR] src/test/java/org/glassfish/grizzly/config/GrizzlyConfigTest.java:[24,8] (imports) UnusedImports: Unused import - java.net.URL.

04:53:58  [ERROR] src/test/java/org/glassfish/grizzly/config/PUGrizzlyConfigTest.java:[27,8] (imports) UnusedImports: Unused import - 

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();

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.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 -1 port, which is why I kept it there. The query-mangling is also why I did not use it in RealmAdapter.
  • 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-encoded getRequestURI()/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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@dmatej dmatej Jun 7, 2026

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.

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.

renatsaf and others added 4 commits June 5, 2026 12:08
… 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

pzygielo commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

please help me with Jenkins results. All builds were made, but somewhat is bad.

I've restarted the job. I suspect some other flaky test in cdi_all.

12:40:06  The domain admin port could not be reached. We will try to kill the process with PID /home/jenkins/agent/workspace/_test-using-jenkinsfile_PR-26051/glassfish8/glassfish/domains/domain1/config/pid.prev

12:40:06  Process with pid 967 has already stopped.

12:40:06  CLI306: Warning - The server located at /home/jenkins/agent/workspace/_test-using-jenkinsfile_PR-26051/glassfish8/glassfish/domains/domain1 is not running.

12:40:06  Command stop-domain executed successfully.

12:40:06  + echo 'Error 1 occurred on 1'

12:40:06  Error 1 occurred on 1

12:40:06  + exit 1

script returned exit code 1

Image

Will check details if the same stage fails again.

@renatsaf

renatsaf commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@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.

@pzygielo

pzygielo commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

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

Copyright (c) {year} Contributors to the Eclipse Foundation

over the inherited Oracle (c) line, like in top level pom:

glassfish/pom.xml

Lines 3 to 6 in 7bf4d70

Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation. All rights reserved.
Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved.

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.

@pzygielo

pzygielo commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

And handbook also has chapter https://www.eclipse.org/projects/handbook/#ai for consideration.

@pzygielo

This comment was marked as resolved.

renatsaf and others added 3 commits June 5, 2026 17:20
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>
@renatsaf

renatsaf commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@pzygielo @dmatej — restructured this PR based on the feedback:

Jenkins compile failures (cdi-all / webservice_all). Root cause was a missing import java.net.URI; in 41 appserv-tests devtests that use URI.create(...). These devtests are compiled by Jenkins but aren't part of the Maven reactor, so the GitHub Actions build stayed green while Jenkins broke with cannot find symbol: variable URI — including the slf4j-visibility/WebTest.java you spotted. All 41 now have the import (alphabetically ordered in the existing java.net group).

Smaller steps (@dmatej). Agreed — this PR is now test code only (the bulk mechanical (new URL(x)).openConnection()URI.create(x).toURL() swaps). The production (src/main) conversions that carry the real encoding/IDN/query semantics — RealmAdapter, WebServiceEndpoint, WebappClassLoader, web-core, webservices, nucleus — plus UrlToUriConversionEquivalenceTest are moving to a separate, focused PR so they can be reviewed on their own. I've changed this PR's body to "Part of #25625"; the production PR will be the one that closes the issue.

License headers (@pzygielo). Added Copyright (c) 2026 Contributors to the Eclipse Foundation. above the inherited copyright line in the touched files that didn't already credit the EF, per the handbook.

@dmatej

dmatej commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@pzygielo As those changes are just in tests, I believe we could squash and merge, what do you think?

@dmatej dmatej added this to the 8.0.4 milestone Jul 16, 2026
@pzygielo

pzygielo commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

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.

@dmatej
dmatej merged commit d6cb48b into eclipse-ee4j:main Jul 25, 2026
1 of 2 checks passed
@dmatej dmatej linked an issue Jul 25, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace all deprecated new URL constructors

3 participants