Skip to content

fix: Normalize bare stylesheet paths to prevent MalformedURLException warnings#24029

Open
Artur- wants to merge 3 commits intomainfrom
fix/stylesheet-path-slash
Open

fix: Normalize bare stylesheet paths to prevent MalformedURLException warnings#24029
Artur- wants to merge 3 commits intomainfrom
fix/stylesheet-path-slash

Conversation

@Artur-
Copy link
Copy Markdown
Member

@Artur- Artur- commented Mar 27, 2026

Bare paths like "lumo/lumo.css" from @Stylesheet annotations cause a MalformedURLException warning because ServletContext.getResource() requires a leading '/'. Normalize the path in ResourceContentHash before calling getStaticResource(), and document the '/' requirement in VaadinService.getStaticResource() javadoc.

Fixes #24028

…ings

Bare paths like "lumo/lumo.css" from @Stylesheet annotations cause a
MalformedURLException warning because ServletContext.getResource()
requires a leading '/'. Normalize the path in ResourceContentHash
before calling getStaticResource(), and document the '/' requirement
in VaadinService.getStaticResource() javadoc.

Fixes #24028
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 27, 2026

Test Results

 1 386 files  ±0   1 386 suites  ±0   1h 25m 30s ⏱️ + 1m 2s
 9 927 tests ±0   9 856 ✅ ±0  71 💤 ±0  0 ❌ ±0 
10 400 runs  ±0  10 320 ✅ ±0  80 💤 ±0  0 ❌ ±0 

Results for commit f20da03. ± Comparison against base commit 482b350.

This pull request removes 1 and adds 1 tests. Note that renamed tests count towards both.
com.vaadin.flow.internal.ResourceContentHashTest ‑ getContentHash_barePath_fallsBackToSlashPrefixed
com.vaadin.flow.internal.ResourceContentHashTest ‑ getContentHash_barePath_normalizedWithSlashPrefix

♻️ This comment has been updated with latest results.

@mcollovati mcollovati changed the title Normalize bare stylesheet paths to prevent MalformedURLException warnings fix: Normalize bare stylesheet paths to prevent MalformedURLException warnings Mar 27, 2026
@mcollovati
Copy link
Copy Markdown
Collaborator

Tested with the Flow CDI starter project, and the exception is not shown anymore.

@Artur- Artur- requested a review from mcollovati March 27, 2026 10:20
Comment on lines +102 to +103
if (resolved.startsWith("./")) {
resolved = resolved.substring(1);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can this assumption cause any problem if VaadinServlet has a custom mapping?
Indeed, in that case the @Stylesheet annotation should use context:// prefix, but I wonder if assuming ./ is relative to the webapp context path could cause problems.

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MalformedURLException when loading style sheets

2 participants