Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate Resource / web-fragment registration #11789

Open
jackeri opened this issue May 14, 2024 · 3 comments
Open

Duplicate Resource / web-fragment registration #11789

jackeri opened this issue May 14, 2024 · 3 comments
Assignees
Labels
Bug For general bugs on Jetty side

Comments

@jackeri
Copy link

jackeri commented May 14, 2024

Jetty version(s)
12.0.9

Jetty Environment
ee10

Java version/vendor (use: java -version)
openjdk 21 2023-09-19 LTS
OpenJDK Runtime Environment Temurin-21+35 (build 21+35-LTS)
OpenJDK 64-Bit Server VM Temurin-21+35 (build 21+35-LTS, mixed mode)

OS type/version
macOS Sonoma 14

Description

When using Jetty as an embedded application server and appending classpath / jar patterns to the runtime context, the final resources list in Metadata.java line 488

resources.addAll(getWebInfResources(isOrdered())); //finally annotations (in order) from webinf path
can end up with duplicates. Depending on which IDE or environment the process in being run in.
When run in Intellij Idea with multiple Gradle modules which are web-fragments of which one is the primary, it gets pushed twice to the resources list, and during runtime the duplicate path registration breaks runtime filters in odd ways.

Simply adding a breakpoint on the line 488, stepping over it and with debug tools remove the duplicate (distinct the list) and the issue gets resolved.

How to reproduce?
Multi module project with one main web app and multiple fragments of which one has

<ordering>
  <before>
    <others/>
  </before>
</ordering>
@jackeri jackeri added the Bug For general bugs on Jetty side label May 14, 2024
jackeri added a commit to jackeri/jetty.project that referenced this issue May 14, 2024
jackeri added a commit to jackeri/jetty.project that referenced this issue May 14, 2024
@janbartel janbartel self-assigned this May 15, 2024
@janbartel
Copy link
Contributor

@jackeri do you have a reproduction ? I can't reproduce it with the information in the PR and our standard jetty-ee10-demo-spec webapp.

@jackeri
Copy link
Author

jackeri commented May 16, 2024

I sadly cannot provide the actual issue project as a sample as it is proprietary software, but essentially having jetty startup from a library module (when I say module I mean a Gradle submodule), and said project having a multiple web-fragments of which one has the ordering set. The dependencies also include spring security, which has a fragment of its own. These all modules are then included with the Gradle "includeBuild" mechanism to the actual Web-application project.

The embedded jetty sets up the required class folders and dependencies with the following patterns for direct disk read:

List<String> jarPatterns = new LinkedList<>();
jarPatterns.add(".*org\\.webjar.*\\.jar$");
jarPatterns.add(".*spring-.*\\.jar$");
// Eclipse specific output path
jarPatterns.add(".*/main/$");

// IntelliJ specific output paths (cls and resources are separated)
jarPatterns.add(".*/production/classes/$");
jarPatterns.add(".*/production/resources/$");

WebAppContext context = new WebAppContext();
context.setAttribute(MetaInfConfiguration.CONTAINER_JAR_PATTERN, String.join("|", jarPatterns));

If the issue really needs an example project, then I can try to provide you with an example setup, but it might take a couple of days for me to get to it. This also only happens with IntelliJ, haven't seen the same issue with Eclipse. The simple fix is to just distinct the resources when loading, as I did in the pull request #11790.

@janbartel
Copy link
Contributor

@jackeri I'm reluctant to change something that doesn't look broken according to our tests, so it would be really great if you can supply a small repro test case that can be loaded into IntelliJ.

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
None yet
Development

No branches or pull requests

2 participants