Skip to content

Commit b5147a0

Browse files
committed
1 parent ebf6fff commit b5147a0

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

spring-beans/src/main/java/org/springframework/beans/propertyeditors/PathEditor.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -98,6 +98,7 @@ public void setAsText(String text) throws IllegalArgumentException {
9898
setValue(null);
9999
}
100100
else if (!resource.isFile() && !resource.exists() && nioPathCandidate) {
101+
// Prefer getFile().toPath() below for non-existent file handles
101102
setValue(Paths.get(text).normalize());
102103
}
103104
else {

spring-beans/src/test/java/org/springframework/beans/propertyeditors/PathEditorTests.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -34,7 +34,7 @@
3434
public class PathEditorTests {
3535

3636
@Test
37-
public void testClasspathPathName() throws Exception {
37+
public void testClasspathPathName() {
3838
PropertyEditor pathEditor = new PathEditor();
3939
pathEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" +
4040
ClassUtils.getShortName(getClass()) + ".class");
@@ -46,14 +46,14 @@ public void testClasspathPathName() throws Exception {
4646
}
4747

4848
@Test
49-
public void testWithNonExistentResource() throws Exception {
49+
public void testWithNonExistentResource() {
5050
PropertyEditor propertyEditor = new PathEditor();
5151
assertThatIllegalArgumentException().isThrownBy(() ->
5252
propertyEditor.setAsText("classpath:/no_way_this_file_is_found.doc"));
5353
}
5454

5555
@Test
56-
public void testWithNonExistentPath() throws Exception {
56+
public void testWithNonExistentPath() {
5757
PropertyEditor pathEditor = new PathEditor();
5858
pathEditor.setAsText("file:/no_way_this_file_is_found.doc");
5959
Object value = pathEditor.getValue();
@@ -65,7 +65,7 @@ public void testWithNonExistentPath() throws Exception {
6565
}
6666

6767
@Test
68-
public void testAbsolutePath() throws Exception {
68+
public void testAbsolutePath() {
6969
PropertyEditor pathEditor = new PathEditor();
7070
pathEditor.setAsText("/no_way_this_file_is_found.doc");
7171
Object value = pathEditor.getValue();
@@ -77,7 +77,7 @@ public void testAbsolutePath() throws Exception {
7777
}
7878

7979
@Test
80-
public void testWindowsAbsolutePath() throws Exception {
80+
public void testWindowsAbsolutePath() {
8181
PropertyEditor pathEditor = new PathEditor();
8282
pathEditor.setAsText("C:\\no_way_this_file_is_found.doc");
8383
Object value = pathEditor.getValue();
@@ -89,7 +89,7 @@ public void testWindowsAbsolutePath() throws Exception {
8989
}
9090

9191
@Test
92-
public void testWindowsAbsoluteFilePath() throws Exception {
92+
public void testWindowsAbsoluteFilePath() {
9393
PropertyEditor pathEditor = new PathEditor();
9494
pathEditor.setAsText("file://C:\\no_way_this_file_is_found.doc");
9595
Object value = pathEditor.getValue();
@@ -101,7 +101,7 @@ public void testWindowsAbsoluteFilePath() throws Exception {
101101
}
102102

103103
@Test
104-
public void testUnqualifiedPathNameFound() throws Exception {
104+
public void testUnqualifiedPathNameFound() {
105105
PropertyEditor pathEditor = new PathEditor();
106106
String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" +
107107
ClassUtils.getShortName(getClass()) + ".class";
@@ -120,7 +120,7 @@ public void testUnqualifiedPathNameFound() throws Exception {
120120
}
121121

122122
@Test
123-
public void testUnqualifiedPathNameNotFound() throws Exception {
123+
public void testUnqualifiedPathNameNotFound() {
124124
PropertyEditor pathEditor = new PathEditor();
125125
String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" +
126126
ClassUtils.getShortName(getClass()) + ".clazz";

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -160,6 +160,8 @@ else if (this.classLoader != null) {
160160
}
161161
}
162162
catch (IllegalArgumentException ex) {
163+
// Should not happen according to the JDK's contract:
164+
// see https://github.com/openjdk/jdk/pull/2662
163165
return null;
164166
}
165167
}

0 commit comments

Comments
 (0)