@@ -74,14 +74,22 @@ public ClassPathResource(String path) {
74
74
*/
75
75
public ClassPathResource (String path , ClassLoader classLoader ) {
76
76
Assert .notNull (path , "Path must not be null" );
77
+ Assert .state (doesNotContainFileColon (path ), "Path must not contain 'file:'" );
78
+
77
79
String pathToUse = StringUtils .cleanPath (path );
80
+
78
81
if (pathToUse .startsWith ("/" )) {
79
82
pathToUse = pathToUse .substring (1 );
80
83
}
84
+
81
85
this .path = pathToUse ;
82
86
this .classLoader = (classLoader != null ? classLoader : ClassUtils .getDefaultClassLoader ());
83
87
}
84
88
89
+ private static boolean doesNotContainFileColon (String path ) {
90
+ return !path .contains ("file:" );
91
+ }
92
+
85
93
/**
86
94
* Create a new ClassPathResource with optional ClassLoader and Class.
87
95
* Only for internal usage.
@@ -108,10 +116,9 @@ public final String getPath() {
108
116
/**
109
117
* This implementation checks for the resolution of a resource URL.
110
118
*
119
+ * @return if exists.
111
120
* @see java.lang.ClassLoader#getResource(String)
112
121
* @see java.lang.Class#getResource(String)
113
- *
114
- * @return if exists.
115
122
*/
116
123
@ Override
117
124
public boolean exists () {
@@ -127,10 +134,9 @@ public boolean exists() {
127
134
/**
128
135
* This implementation opens an InputStream for the given class path resource.
129
136
*
137
+ * @return the input stream.
130
138
* @see java.lang.ClassLoader#getResourceAsStream(String)
131
139
* @see java.lang.Class#getResourceAsStream(String)
132
- *
133
- * @return the input stream.
134
140
*/
135
141
@ Override
136
142
public InputStream getInputStream () throws IOException {
@@ -149,10 +155,9 @@ public InputStream getInputStream() throws IOException {
149
155
/**
150
156
* This implementation returns a URL for the underlying class path resource.
151
157
*
158
+ * @return the url.
152
159
* @see java.lang.ClassLoader#getResource(String)
153
160
* @see java.lang.Class#getResource(String)
154
- *
155
- * @return the url.
156
161
*/
157
162
@ Override
158
163
public URL getURL () throws IOException {
@@ -172,9 +177,8 @@ public URL getURL() throws IOException {
172
177
* This implementation creates a ClassPathResource, applying the given path
173
178
* relative to the path of the underlying resource of this descriptor.
174
179
*
175
- * @see spark.utils.StringUtils#applyRelativePath(String, String)
176
- *
177
180
* @return the resource.
181
+ * @see spark.utils.StringUtils#applyRelativePath(String, String)
178
182
*/
179
183
@ Override
180
184
public Resource createRelative (String relativePath ) {
@@ -186,9 +190,8 @@ public Resource createRelative(String relativePath) {
186
190
* This implementation returns the name of the file that this class path
187
191
* resource refers to.
188
192
*
189
- * @see spark.utils.StringUtils#getFilename(String)
190
- *
191
193
* @return the file name.
194
+ * @see spark.utils.StringUtils#getFilename(String)
192
195
*/
193
196
@ Override
194
197
public String getFilename () {
@@ -233,8 +236,8 @@ public boolean equals(Object obj) {
233
236
ClassLoader otherLoader = otherRes .classLoader ;
234
237
235
238
return (this .path .equals (otherRes .path ) &&
236
- thisLoader .equals (otherLoader ) &&
237
- this .clazz .equals (otherRes .clazz ));
239
+ thisLoader .equals (otherLoader ) &&
240
+ this .clazz .equals (otherRes .clazz ));
238
241
}
239
242
return false ;
240
243
}
0 commit comments