Skip to content

fix: wrong existence check in getStaticResource (CP: 25.0)#24285

Merged
caalador merged 1 commit into25.0from
cherry/cherrypick-24283-to-25.0
May 7, 2026
Merged

fix: wrong existence check in getStaticResource (CP: 25.0)#24285
caalador merged 1 commit into25.0from
cherry/cherrypick-24283-to-25.0

Conversation

@mcollovati
Copy link
Copy Markdown
Collaborator

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.

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.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 7, 2026

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Test Results

1 319 files  ±0  1 319 suites  ±0   1h 11m 18s ⏱️ - 3m 18s
9 419 tests +1  9 352 ✅ +1  67 💤 ±0  0 ❌ ±0 
9 869 runs  ±0  9 795 ✅ ±0  74 💤 ±0  0 ❌ ±0 

Results for commit a43d2b8. ± Comparison against base commit 755c836.

@mcollovati mcollovati marked this pull request as ready for review May 7, 2026 10:17
@caalador caalador merged commit 2142a79 into 25.0 May 7, 2026
30 checks passed
@caalador caalador deleted the cherry/cherrypick-24283-to-25.0 branch May 7, 2026 10:20
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