Skip to content

Issue #15228 - Deprecate use of newResource() during webapp started phase.#15231

Merged
joakime merged 7 commits into
jetty-12.1.xfrom
fix/12.1.x/15228/servletcontext.getresourceasstream
Jun 12, 2026
Merged

Issue #15228 - Deprecate use of newResource() during webapp started phase.#15231
joakime merged 7 commits into
jetty-12.1.xfrom
fix/12.1.x/15228/servletcontext.getresourceasstream

Conversation

@joakime

@joakime joakime commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

With the removal of FileSystemPool (PR #14826), the Resource and ResourceFactory APIs are more strict in usage.
The old techniques (pre Jetty 12) where a call to newResource() and resolve() were identical in behavior are no longer true.
Any call to newResource() has the potential to create a new FileSystem object instance (true for non-file schema URIs, like jar:file:///path/to/foo.jar, or resources://, or bundle://, etc)

That means we need to stop using newResource() during the started phase in a webapp, and only rely on the resolve() methods to find new Jetty Resource objects.

This PR deprecates all of the various newResource() APIs that can be used during the started phase of a webapp, and changes all of the calls to these newly deprecated APIs to use the appropriate API based on the when the Resource is needed, and for how long it is being tracked.

joakime added 2 commits June 4, 2026 09:22
…hase.

Only valid use of newResource() is during webapp setup or initialization.
@joakime joakime requested a review from lorban June 4, 2026 14:38
@joakime joakime self-assigned this Jun 4, 2026
@joakime joakime added the Bug For general bugs on Jetty side label Jun 4, 2026
@joakime joakime moved this to 👀 In review in Jetty 12.1.11 Jun 4, 2026
@joakime joakime requested a review from lorban June 5, 2026 22:12

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

There are still pending comments, but that change is almost there.

@joakime joakime requested a review from lorban June 9, 2026 19:27

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

If you copy/adapt the ServletContextHandlerTest changes to EE9 and EE10 then this LGTM.

Object trackedResources = mbeanServer.getAttribute(objectName, "trackedResources");
assertNotNull(trackedResources);
assertThat(trackedResources, instanceOf(List.class));
if (trackedResources instanceof List<?> trackedList)

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.

You could just cast trackedResources to List, but fine.

@joakime joakime requested a review from lorban June 10, 2026 16:07
@joakime joakime merged commit b4fba92 into jetty-12.1.x Jun 12, 2026
11 checks passed
@github-project-automation github-project-automation Bot moved this from 👀 In review to ✅ Done in Jetty 12.1.11 Jun 12, 2026
@joakime joakime deleted the fix/12.1.x/15228/servletcontext.getresourceasstream branch June 12, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug For general bugs on Jetty side

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants