@@ -368,7 +368,7 @@ protected void addAllClassLoaderJarRoots(ClassLoader classLoader, Set<Resource>
368
368
for (URL url : ((URLClassLoader ) classLoader ).getURLs ()) {
369
369
try {
370
370
UrlResource jarResource = new UrlResource (
371
- ResourceUtils .JAR_URL_PREFIX + url . toString () + ResourceUtils .JAR_URL_SEPARATOR );
371
+ ResourceUtils .JAR_URL_PREFIX + url + ResourceUtils .JAR_URL_SEPARATOR );
372
372
if (jarResource .exists ()) {
373
373
result .add (jarResource );
374
374
}
@@ -420,11 +420,11 @@ protected void addClassPathManifestEntries(Set<Resource> result) {
420
420
for (String path : StringUtils .delimitedListToStringArray (
421
421
javaClassPathProperty , System .getProperty ("path.separator" ))) {
422
422
try {
423
- File file = new File (path );
423
+ String filePath = new File (path ). getAbsolutePath ( );
424
424
UrlResource jarResource = new UrlResource (ResourceUtils .JAR_URL_PREFIX +
425
- ResourceUtils .FILE_URL_PREFIX + file . getAbsolutePath () +
426
- ResourceUtils . JAR_URL_SEPARATOR );
427
- if (jarResource .exists ()) {
425
+ ResourceUtils .FILE_URL_PREFIX + filePath + ResourceUtils . JAR_URL_SEPARATOR );
426
+ // Potentially overlapping with URLClassLoader.getURLs() result above!
427
+ if (! result . contains ( jarResource ) && ! hasDuplicate ( filePath , result ) && jarResource .exists ()) {
428
428
result .add (jarResource );
429
429
}
430
430
}
@@ -443,6 +443,29 @@ protected void addClassPathManifestEntries(Set<Resource> result) {
443
443
}
444
444
}
445
445
446
+ /**
447
+ * Check whether the given file path has a duplicate but differently structured entry
448
+ * in the existing result, i.e. with or without a leading slash.
449
+ * @param filePath the file path (with or without a leading slash)
450
+ * @param result the current result
451
+ * @return {@code true} if there is a duplicate (i.e. to ignore the given file path),
452
+ * {@code false} to proceed with adding a corresponding resource to the current result
453
+ */
454
+ private boolean hasDuplicate (String filePath , Set <Resource > result ) {
455
+ if (result .isEmpty ()) {
456
+ return false ;
457
+ }
458
+ String duplicatePath = (filePath .startsWith ("/" ) ? filePath .substring (1 ) : "/" + filePath );
459
+ try {
460
+ return result .contains (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX +
461
+ duplicatePath + ResourceUtils .JAR_URL_SEPARATOR ));
462
+ }
463
+ catch (MalformedURLException ex ) {
464
+ // Ignore: just for testing against duplicate.
465
+ return false ;
466
+ }
467
+ }
468
+
446
469
/**
447
470
* Find all resources that match the given location pattern via the
448
471
* Ant-style PathMatcher. Supports resources in jar files and zip files
0 commit comments