@@ -74,14 +74,22 @@ public ClassPathResource(String path) {
7474 */
7575 public ClassPathResource (String path , ClassLoader classLoader ) {
7676 Assert .notNull (path , "Path must not be null" );
77+ Assert .state (doesNotContainFileColon (path ), "Path must not contain 'file:'" );
78+
7779 String pathToUse = StringUtils .cleanPath (path );
80+
7881 if (pathToUse .startsWith ("/" )) {
7982 pathToUse = pathToUse .substring (1 );
8083 }
84+
8185 this .path = pathToUse ;
8286 this .classLoader = (classLoader != null ? classLoader : ClassUtils .getDefaultClassLoader ());
8387 }
8488
89+ private static boolean doesNotContainFileColon (String path ) {
90+ return !path .contains ("file:" );
91+ }
92+
8593 /**
8694 * Create a new ClassPathResource with optional ClassLoader and Class.
8795 * Only for internal usage.
@@ -108,10 +116,9 @@ public final String getPath() {
108116 /**
109117 * This implementation checks for the resolution of a resource URL.
110118 *
119+ * @return if exists.
111120 * @see java.lang.ClassLoader#getResource(String)
112121 * @see java.lang.Class#getResource(String)
113- *
114- * @return if exists.
115122 */
116123 @ Override
117124 public boolean exists () {
@@ -127,10 +134,9 @@ public boolean exists() {
127134 /**
128135 * This implementation opens an InputStream for the given class path resource.
129136 *
137+ * @return the input stream.
130138 * @see java.lang.ClassLoader#getResourceAsStream(String)
131139 * @see java.lang.Class#getResourceAsStream(String)
132- *
133- * @return the input stream.
134140 */
135141 @ Override
136142 public InputStream getInputStream () throws IOException {
@@ -149,10 +155,9 @@ public InputStream getInputStream() throws IOException {
149155 /**
150156 * This implementation returns a URL for the underlying class path resource.
151157 *
158+ * @return the url.
152159 * @see java.lang.ClassLoader#getResource(String)
153160 * @see java.lang.Class#getResource(String)
154- *
155- * @return the url.
156161 */
157162 @ Override
158163 public URL getURL () throws IOException {
@@ -172,9 +177,8 @@ public URL getURL() throws IOException {
172177 * This implementation creates a ClassPathResource, applying the given path
173178 * relative to the path of the underlying resource of this descriptor.
174179 *
175- * @see spark.utils.StringUtils#applyRelativePath(String, String)
176- *
177180 * @return the resource.
181+ * @see spark.utils.StringUtils#applyRelativePath(String, String)
178182 */
179183 @ Override
180184 public Resource createRelative (String relativePath ) {
@@ -186,9 +190,8 @@ public Resource createRelative(String relativePath) {
186190 * This implementation returns the name of the file that this class path
187191 * resource refers to.
188192 *
189- * @see spark.utils.StringUtils#getFilename(String)
190- *
191193 * @return the file name.
194+ * @see spark.utils.StringUtils#getFilename(String)
192195 */
193196 @ Override
194197 public String getFilename () {
@@ -233,8 +236,8 @@ public boolean equals(Object obj) {
233236 ClassLoader otherLoader = otherRes .classLoader ;
234237
235238 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 ));
238241 }
239242 return false ;
240243 }
0 commit comments