Skip to content

fix: wrong existence check in getStaticResource#24283

Merged
mcollovati merged 1 commit intomainfrom
fix/jetty-static-resources-workaroud
May 7, 2026
Merged

fix: wrong existence check in getStaticResource#24283
mcollovati merged 1 commit intomainfrom
fix/jetty-static-resources-workaroud

Conversation

@mcollovati
Copy link
Copy Markdown
Collaborator

On Jetty 12.1.9, requests for static resources packaged inside a JAR (e.g. vaadinPush.js from flow-push) fail with
FileSystemNotFoundException. VaadinServletService.getStaticResource verifies the URL returned by ServletContext.getResource via Path.of(url.toURI()), which for a jar:file:...!/entry URI requires the JAR's NIO FileSystem to already be mounted in the JVM-wide cache. Jetty 12.1.8 incidentally kept those filesystems mounted during resource resolution; 12.1.9 no longer does, so getFileSystem throws and the existing catch (URISyntaxException) lets the unchecked exception escape, producing HTTP 500.

Probe the URL with URL.openStream() instead. JarURLConnection and FileURLConnection use java.util.jar.JarFile / java.io.File directly and are independent of the NIO FileSystems cache, so the check works uniformly for file: and jar:file: URLs and on every Jetty 12 build. The catch is broadened to IOException, covering both missing files (the original Jetty 12 workaround) and missing JAR entries.

On Jetty 12.1.9, requests for static resources packaged inside a JAR
(e.g. `vaadinPush.js` from `flow-push`) fail with
`FileSystemNotFoundException`. `VaadinServletService.getStaticResource`
verifies the URL returned by `ServletContext.getResource` via
`Path.of(url.toURI())`, which for a `jar:file:...!/entry` URI requires
the JAR's NIO `FileSystem` to already be mounted in the JVM-wide cache.
Jetty 12.1.8 incidentally kept those filesystems mounted during
resource resolution; 12.1.9 no longer does, so `getFileSystem` throws
and the existing `catch (URISyntaxException)` lets the unchecked
exception escape, producing HTTP 500.

Probe the URL with `URL.openStream()` instead. `JarURLConnection` and
`FileURLConnection` use `java.util.jar.JarFile` / `java.io.File`
directly and are independent of the NIO `FileSystems` cache, so the
check works uniformly for `file:` and `jar:file:` URLs and on every
Jetty 12 build. The catch is broadened to `IOException`, covering both
missing files (the original Jetty 12 workaround) and missing JAR
entries.
@mcollovati
Copy link
Copy Markdown
Collaborator Author

Tested in #24274
I'll remove the commit in that PR if this one gets merged.

@github-actions github-actions Bot added the +0.0.1 label May 7, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 7, 2026

@mcollovati mcollovati enabled auto-merge May 7, 2026 08:33
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Test Results

 1 404 files  ±0   1 404 suites  ±0   1h 16m 16s ⏱️ -25s
10 128 tests +1  10 058 ✅ +1  70 💤 ±0  0 ❌ ±0 
10 603 runs  +1  10 524 ✅ +1  79 💤 ±0  0 ❌ ±0 

Results for commit 4a11ad3. ± Comparison against base commit 687bae0.

@mcollovati mcollovati added this pull request to the merge queue May 7, 2026
Merged via the queue into main with commit a26aa80 May 7, 2026
31 checks passed
@mcollovati mcollovati deleted the fix/jetty-static-resources-workaroud branch May 7, 2026 08:54
@vaadin-bot
Copy link
Copy Markdown
Collaborator

Hi @mcollovati and @mcollovati, when i performed cherry-pick to this commit to 24.10, i have encountered the following issue. Can you take a look and pick it manually?
Error Message:
Error: Command failed: git cherry-pick a26aa80
error: could not apply a26aa80... fix: wrong existence check in getStaticResource (#24283)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

@vaadin-bot
Copy link
Copy Markdown
Collaborator

Hi @mcollovati and @mcollovati, when i performed cherry-pick to this commit to 25.0, i have encountered the following issue. Can you take a look and pick it manually?
Error Message:
Error: Command failed: git cherry-pick a26aa80
error: could not apply a26aa80... fix: wrong existence check in getStaticResource (#24283)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

@vaadin-bot
Copy link
Copy Markdown
Collaborator

Hi @mcollovati and @mcollovati, when i performed cherry-pick to this commit to 24.9, i have encountered the following issue. Can you take a look and pick it manually?
Error Message:
Error: Command failed: git cherry-pick a26aa80
error: could not apply a26aa80... fix: wrong existence check in getStaticResource (#24283)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

vaadin-bot added a commit that referenced this pull request May 7, 2026
…24284)

This PR cherry-picks changes from the original PR #24283 to branch 25.1.
---
#### Original PR description
> On Jetty 12.1.9, requests for static resources packaged inside a JAR
(e.g. `vaadinPush.js` from `flow-push`) fail with
> `FileSystemNotFoundException`.
`VaadinServletService.getStaticResource` verifies the URL returned by
`ServletContext.getResource` via `Path.of(url.toURI())`, which for a
`jar:file:...!/entry` URI requires the JAR's NIO `FileSystem` to already
be mounted in the JVM-wide cache. Jetty 12.1.8 incidentally kept those
filesystems mounted during resource resolution; 12.1.9 no longer does,
so `getFileSystem` throws and the existing `catch (URISyntaxException)`
lets the unchecked exception escape, producing HTTP 500.
> 
> Probe the URL with `URL.openStream()` instead. `JarURLConnection` and
`FileURLConnection` use `java.util.jar.JarFile` / `java.io.File`
directly and are independent of the NIO `FileSystems` cache, so the
check works uniformly for `file:` and `jar:file:` URLs and on every
Jetty 12 build. The catch is broadened to `IOException`, covering both
missing files (the original Jetty 12 workaround) and missing JAR
entries.
>

Co-authored-by: Marco Collovati <marco@vaadin.com>
caalador pushed a commit that referenced this pull request May 7, 2026
This PR cherry-picks changes from the original PR #24283 to branch 25.0.

A conflict in
`flow-server/src/test/java/com/vaadin/flow/server/VaadinServletServiceTest.java`
was resolved manually: the new
`getStaticResource_jarUrlOnJetty12_returnsUrlInsteadOfThrowing` test was
rewritten in JUnit 4 idioms (`@Rule TemporaryFolder`, `Assert.*`) since
25.0 has not adopted the JUnit 5 migration that landed on `main`.
vaadin-bot added a commit that referenced this pull request May 7, 2026
…CP: 24.10) (#24286)

This PR cherry-picks changes from the original PR #24285 to branch
24.10.
---
#### Original PR description
> This PR cherry-picks changes from the original PR #24283 to branch
25.0.
> 
> A conflict in
`flow-server/src/test/java/com/vaadin/flow/server/VaadinServletServiceTest.java`
was resolved manually: the new
`getStaticResource_jarUrlOnJetty12_returnsUrlInsteadOfThrowing` test was
rewritten in JUnit 4 idioms (`@Rule TemporaryFolder`, `Assert.*`) since
25.0 has not adopted the JUnit 5 migration that landed on `main`.
> 
> ---
> 
> > On Jetty 12.1.9, requests for static resources packaged inside a JAR
(e.g. `vaadinPush.js` from `flow-push`) fail with
> > `FileSystemNotFoundException`.
`VaadinServletService.getStaticResource` verifies the URL returned by
`ServletContext.getResource` via `Path.of(url.toURI())`, which for a
`jar:file:...!/entry` URI requires the JAR's NIO `FileSystem` to already
be mounted in the JVM-wide cache. Jetty 12.1.8 incidentally kept those
filesystems mounted during resource resolution; 12.1.9 no longer does,
so `getFileSystem` throws and the existing `catch (URISyntaxException)`
lets the unchecked exception escape, producing HTTP 500.
> >
> > Probe the URL with `URL.openStream()` instead. `JarURLConnection`
and `FileURLConnection` use `java.util.jar.JarFile` / `java.io.File`
directly and are independent of the NIO `FileSystems` cache, so the
check works uniformly for `file:` and `jar:file:` URLs and on every
Jetty 12 build. The catch is broadened to `IOException`, covering both
missing files (the original Jetty 12 workaround) and missing JAR
entries.

Co-authored-by: Marco Collovati <marco@vaadin.com>
vaadin-bot added a commit that referenced this pull request May 7, 2026
…CP: 24.9) (#24287)

This PR cherry-picks changes from the original PR #24285 to branch 24.9.
---
#### Original PR description
> This PR cherry-picks changes from the original PR #24283 to branch
25.0.
> 
> A conflict in
`flow-server/src/test/java/com/vaadin/flow/server/VaadinServletServiceTest.java`
was resolved manually: the new
`getStaticResource_jarUrlOnJetty12_returnsUrlInsteadOfThrowing` test was
rewritten in JUnit 4 idioms (`@Rule TemporaryFolder`, `Assert.*`) since
25.0 has not adopted the JUnit 5 migration that landed on `main`.
> 
> ---
> 
> > On Jetty 12.1.9, requests for static resources packaged inside a JAR
(e.g. `vaadinPush.js` from `flow-push`) fail with
> > `FileSystemNotFoundException`.
`VaadinServletService.getStaticResource` verifies the URL returned by
`ServletContext.getResource` via `Path.of(url.toURI())`, which for a
`jar:file:...!/entry` URI requires the JAR's NIO `FileSystem` to already
be mounted in the JVM-wide cache. Jetty 12.1.8 incidentally kept those
filesystems mounted during resource resolution; 12.1.9 no longer does,
so `getFileSystem` throws and the existing `catch (URISyntaxException)`
lets the unchecked exception escape, producing HTTP 500.
> >
> > Probe the URL with `URL.openStream()` instead. `JarURLConnection`
and `FileURLConnection` use `java.util.jar.JarFile` / `java.io.File`
directly and are independent of the NIO `FileSystems` cache, so the
check works uniformly for `file:` and `jar:file:` URLs and on every
Jetty 12 build. The catch is broadened to `IOException`, covering both
missing files (the original Jetty 12 workaround) and missing JAR
entries.

Co-authored-by: Marco Collovati <marco@vaadin.com>
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.

3 participants