Skip to content

Commit fa9a7b1

Browse files
committed
refined Resource "exists()" check for HTTP URLs to always return false for 404 status (SPR-7881)
1 parent 2cb287a commit fa9a7b1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

org.springframework.core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2011 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.
@@ -100,9 +100,13 @@ public boolean exists() {
100100
(con instanceof HttpURLConnection ? (HttpURLConnection) con : null);
101101
if (httpCon != null) {
102102
httpCon.setRequestMethod("HEAD");
103-
if (httpCon.getResponseCode() == HttpURLConnection.HTTP_OK) {
103+
int code = httpCon.getResponseCode();
104+
if (code == HttpURLConnection.HTTP_OK) {
104105
return true;
105106
}
107+
else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
108+
return false;
109+
}
106110
}
107111
if (con.getContentLength() >= 0) {
108112
return true;

0 commit comments

Comments
 (0)