Skip to content

Commit 84be0d8

Browse files
committed
Refine location checks for PathResource
This commit ensures that checks for PathResource locations are skipped because this resource implementation will always resolve under the current location. Closes gh-34167
1 parent c971276 commit 84be0d8

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceHandlerUtils.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424
import org.apache.commons.logging.LogFactory;
2525

2626
import org.springframework.core.io.ClassPathResource;
27+
import org.springframework.core.io.PathResource;
2728
import org.springframework.core.io.Resource;
2829
import org.springframework.core.io.UrlResource;
2930
import org.springframework.core.log.LogFormatUtils;
@@ -56,7 +57,10 @@ public static void assertResourceLocation(@Nullable Resource location) {
5657
Assert.notNull(location, "Resource location must not be null");
5758
try {
5859
String path;
59-
if (location instanceof UrlResource) {
60+
if (location instanceof PathResource) {
61+
return;
62+
}
63+
else if (location instanceof UrlResource) {
6064
path = location.getURL().toExternalForm();
6165
}
6266
else if (location instanceof ClassPathResource classPathResource) {

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHandlerUtils.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424
import org.apache.commons.logging.LogFactory;
2525

2626
import org.springframework.core.io.ClassPathResource;
27+
import org.springframework.core.io.PathResource;
2728
import org.springframework.core.io.Resource;
2829
import org.springframework.core.io.UrlResource;
2930
import org.springframework.core.log.LogFormatUtils;
@@ -57,7 +58,10 @@ public static void assertResourceLocation(@Nullable Resource location) {
5758
Assert.notNull(location, "Resource location must not be null");
5859
try {
5960
String path;
60-
if (location instanceof UrlResource) {
61+
if (location instanceof PathResource) {
62+
return;
63+
}
64+
else if (location instanceof UrlResource) {
6165
path = location.getURL().toExternalForm();
6266
}
6367
else if (location instanceof ClassPathResource classPathResource) {

0 commit comments

Comments
 (0)