File tree Expand file tree Collapse file tree 4 files changed +29
-14
lines changed
main/java/org/springframework/core/io
test/java/org/springframework/core/io
spring-web/src/main/java/org/springframework/web/context/support Expand file tree Collapse file tree 4 files changed +29
-14
lines changed Original file line number Diff line number Diff line change @@ -220,6 +220,16 @@ public String getFilename() {
220
220
return null ;
221
221
}
222
222
223
+ /**
224
+ * Lazily access the logger for debug logging in case of an exception.
225
+ */
226
+ private void debug (Supplier <String > message , Throwable ex ) {
227
+ Log logger = LogFactory .getLog (getClass ());
228
+ if (logger .isDebugEnabled ()) {
229
+ logger .debug (message .get (), ex );
230
+ }
231
+ }
232
+
223
233
224
234
/**
225
235
* This implementation compares description strings.
@@ -249,11 +259,4 @@ public String toString() {
249
259
return getDescription ();
250
260
}
251
261
252
- private void debug (Supplier <String > message , Throwable ex ) {
253
- Log logger = LogFactory .getLog (getClass ());
254
- if (logger .isDebugEnabled ()) {
255
- logger .debug (message .get (), ex );
256
- }
257
- }
258
-
259
262
}
Original file line number Diff line number Diff line change @@ -257,7 +257,7 @@ public String getFilename() {
257
257
*/
258
258
@ Override
259
259
public String getDescription () {
260
- return "class path resource [" + this .absolutePath + ']' ;
260
+ return "class path resource [" + this .absolutePath + "]" ;
261
261
}
262
262
263
263
@@ -272,7 +272,7 @@ public boolean equals(@Nullable Object obj) {
272
272
if (this == obj ) {
273
273
return true ;
274
274
}
275
- return (( obj instanceof ClassPathResource that ) &&
275
+ return (obj instanceof ClassPathResource that &&
276
276
this .absolutePath .equals (that .absolutePath ) &&
277
277
ObjectUtils .nullSafeEquals (getClassLoader (), that .getClassLoader ()));
278
278
}
Original file line number Diff line number Diff line change @@ -70,19 +70,19 @@ private static String platformPath(String string) {
70
70
@ Test
71
71
void nullPath () {
72
72
assertThatIllegalArgumentException ().isThrownBy (() -> new PathResource ((Path ) null ))
73
- .withMessageContaining ("Path must not be null" );
73
+ .withMessageContaining ("Path must not be null" );
74
74
}
75
75
76
76
@ Test
77
77
void nullPathString () {
78
78
assertThatIllegalArgumentException ().isThrownBy (() -> new PathResource ((String ) null ))
79
- .withMessageContaining ("Path must not be null" );
79
+ .withMessageContaining ("Path must not be null" );
80
80
}
81
81
82
82
@ Test
83
83
void nullUri () {
84
84
assertThatIllegalArgumentException ().isThrownBy (() -> new PathResource ((URI ) null ))
85
- .withMessageContaining ("URI must not be null" );
85
+ .withMessageContaining ("URI must not be null" );
86
86
}
87
87
88
88
@ Test
@@ -258,6 +258,17 @@ void directoryIsNotWritable() {
258
258
assertThat (resource .isWritable ()).isFalse ();
259
259
}
260
260
261
+ @ Test
262
+ void equalsAndHashCode () {
263
+ Resource mr1 = new PathResource (TEST_FILE );
264
+ Resource mr2 = new PathResource (TEST_FILE );
265
+ Resource mr3 = new PathResource (TEST_DIR );
266
+ assertThat (mr1 ).isEqualTo (mr2 );
267
+ assertThat (mr1 ).isNotEqualTo (mr3 );
268
+ assertThat (mr1 ).hasSameHashCodeAs (mr2 );
269
+ assertThat (mr1 ).doesNotHaveSameHashCodeAs (mr3 );
270
+ }
271
+
261
272
@ Test
262
273
void outputStream (@ TempDir Path temporaryFolder ) throws IOException {
263
274
PathResource resource = new PathResource (temporaryFolder .resolve ("test" ));
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@ public class ServletContextResource extends AbstractFileResolvingResource implem
57
57
58
58
59
59
/**
60
- * Create a new ServletContextResource.
60
+ * Create a new {@code ServletContextResource} for the given path .
61
61
* <p>The Servlet spec requires that resource paths start with a slash,
62
62
* even if many containers accept paths without leading slash too.
63
63
* Consequently, the given path will be prepended with a slash if it
@@ -94,6 +94,7 @@ public final String getPath() {
94
94
return this .path ;
95
95
}
96
96
97
+
97
98
/**
98
99
* This implementation checks {@code ServletContext.getResource}.
99
100
* @see jakarta.servlet.ServletContext#getResource(String)
You can’t perform that action at this time.
0 commit comments