Skip to content

Commit 0c39fff

Browse files
committed
Polishing
1 parent e902f95 commit 0c39fff

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

spring-core/src/main/java/org/springframework/core/io/AbstractResource.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,16 @@ public String getFilename() {
220220
return null;
221221
}
222222

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+
223233

224234
/**
225235
* This implementation compares description strings.
@@ -249,11 +259,4 @@ public String toString() {
249259
return getDescription();
250260
}
251261

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-
259262
}

spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public String getFilename() {
257257
*/
258258
@Override
259259
public String getDescription() {
260-
return "class path resource [" + this.absolutePath + ']';
260+
return "class path resource [" + this.absolutePath + "]";
261261
}
262262

263263

@@ -272,7 +272,7 @@ public boolean equals(@Nullable Object obj) {
272272
if (this == obj) {
273273
return true;
274274
}
275-
return ((obj instanceof ClassPathResource that) &&
275+
return (obj instanceof ClassPathResource that &&
276276
this.absolutePath.equals(that.absolutePath) &&
277277
ObjectUtils.nullSafeEquals(getClassLoader(), that.getClassLoader()));
278278
}

spring-core/src/test/java/org/springframework/core/io/PathResourceTests.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,19 @@ private static String platformPath(String string) {
7070
@Test
7171
void nullPath() {
7272
assertThatIllegalArgumentException().isThrownBy(() -> new PathResource((Path) null))
73-
.withMessageContaining("Path must not be null");
73+
.withMessageContaining("Path must not be null");
7474
}
7575

7676
@Test
7777
void nullPathString() {
7878
assertThatIllegalArgumentException().isThrownBy(() -> new PathResource((String) null))
79-
.withMessageContaining("Path must not be null");
79+
.withMessageContaining("Path must not be null");
8080
}
8181

8282
@Test
8383
void nullUri() {
8484
assertThatIllegalArgumentException().isThrownBy(() -> new PathResource((URI) null))
85-
.withMessageContaining("URI must not be null");
85+
.withMessageContaining("URI must not be null");
8686
}
8787

8888
@Test
@@ -258,6 +258,17 @@ void directoryIsNotWritable() {
258258
assertThat(resource.isWritable()).isFalse();
259259
}
260260

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+
261272
@Test
262273
void outputStream(@TempDir Path temporaryFolder) throws IOException {
263274
PathResource resource = new PathResource(temporaryFolder.resolve("test"));

spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -57,7 +57,7 @@ public class ServletContextResource extends AbstractFileResolvingResource implem
5757

5858

5959
/**
60-
* Create a new ServletContextResource.
60+
* Create a new {@code ServletContextResource} for the given path.
6161
* <p>The Servlet spec requires that resource paths start with a slash,
6262
* even if many containers accept paths without leading slash too.
6363
* Consequently, the given path will be prepended with a slash if it
@@ -94,6 +94,7 @@ public final String getPath() {
9494
return this.path;
9595
}
9696

97+
9798
/**
9899
* This implementation checks {@code ServletContext.getResource}.
99100
* @see jakarta.servlet.ServletContext#getResource(String)

0 commit comments

Comments
 (0)