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

PathResourceResolver.getResource() does not log warning if Resource#getURL() throws exception #31623

Closed
matthiaskraaz opened this issue Nov 19, 2023 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@matthiaskraaz
Copy link

matthiaskraaz commented Nov 19, 2023

If ServletContextResource.getURL() throws a FileNotFoundException because ServletContext.getResource(String) returns null, then org.springframework.web.servlet.resource.PathResourceResolver.getResource(String, Resource) does not log a warning as intended.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 19, 2023
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Nov 19, 2023
@sbrannen sbrannen changed the title org.springframework.web.servlet.resource.PathResourceResolver.getResource never logs a warning Servlet-based PathResourceResolver.getResource() never logs a warning for non-existent ServletContextResource Nov 19, 2023
@sbrannen sbrannen added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 19, 2023
@sbrannen sbrannen self-assigned this Nov 19, 2023
@sbrannen
Copy link
Member

Hi @matthiaskraaz,

Congratulations on reporting your first issue for the Spring Framework! 👍

I have a fix prepared locally, and we'll make sure to include it in the next release.

@sbrannen sbrannen added this to the 6.1.1 milestone Nov 19, 2023
@sbrannen sbrannen added the for: backport-to-6.0.x Marks an issue as a candidate for backport to 6.0.x label Nov 19, 2023
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-6.0.x Marks an issue as a candidate for backport to 6.0.x labels Nov 19, 2023
@sbrannen sbrannen changed the title Servlet-based PathResourceResolver.getResource() never logs a warning for non-existent ServletContextResource PathResourceResolver.getResource() does not log warning if Resource#getURL() throws exception Nov 20, 2023
sbrannen added a commit that referenced this issue Nov 20, 2023
Prior to this commit, the getResource() methods in PathResourceResolver
implementations allowed an exception thrown from Resource#getURL() to
propagate instead of logging a warning about the missing resource as
intended.

This commit modifies the getResource() methods in PathResourceResolver
implementations so that the log messages include the output of the
toString() implementations of the underlying resources instead of their
getURL() implementations, which may throw an exception.

Furthermore, logging the toString() output of resources aligns with the
existing output for "allowed locations" in the same log message.

Note that the toString() implementations could potentially also throw
exceptions, but that is considered less likely.

See gh-31623
Closes gh-31624

(cherry picked from commit 7d2ea7e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants