Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PathMatchingResourcePatternResolver returns duplicate resources when using classpath*: prefix [SPR-16117] #20665

Closed
spring-projects-issues opened this issue Oct 25, 2017 · 11 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Oct 25, 2017

Udayakumar opened SPR-16117 and commented

I am working on a drools project. The goal is to search all the rules(*.rdrl) files in the classpath and write it into the KieFileSystem. The rules file(.rdrl) will be present under multiple jar files. These jar files were added as a dependency in the drools project.
Below is the code that is used to find all the .rdrl files.

ClassLoader classloader = this.getClass().getClassLoader();
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(classloader);

for (Resource file : resourcePatternResolver.getResources("classpath*:/**/*.rdrl")) {
System.out.println("name: " + file.getURL());
kieFileSystem.write(ResourceFactory.newUrlResource(file.getURL()));
}

Below is the sample output printed by the above code

name: jar:file:/C:/mvn_repo/com/myteam/OOP_Modular/1.0.0/OOP_Modular-1.0.0.jar!/com/myteam/oop_modular/OOP_MOD_Network_In_Network.rdrl

name: jar:file:/C:/mvn_repo/com/myteam/OOP_Modular/1.0.0/OOP_Modular-1.0.0.jar!/com/myteam/oop_modular/OOP_MOD_Individual1.rdrl

name: jar:file:c:\mvn_repo\com\myteam\OOP_Modular\1.0.0\OOP_Modular-1.0.0.jar!/com/myteam/oop_modular/OOP_MOD_Network_In_Network.rdrl

name: jar:file:c:\mvn_repo\com\myteam\OOP_Modular\1.0.0\OOP_Modular-1.0.0.jar!/com/myteam/oop_modular/OOP_MOD_Individual1.rdrl

As seen from the above output there are two entries for the same files OOP_MOD_Network_In_Network.rdrl and OOP_MOD_Individual1.rdrl. When you look at the output, the path is exactly same except that one starts with /C: and other with c:

Because of this issue, since i am trying to write each rule twice into kiefilesystem, it throws an exception saying "Duplicate rule name".

Note: When using pattern such as ("classpath*:com/**/*.rdrl"), the resources are returned only once but we are not sure if the rules file will be present only under 'com', it can also be under 'org' or anything else.

System: Windows 7, JDK 1.8


Affects: 4.3.12, 5.0.1

Issue Links:

Referenced from: commits 8904de2, a2f5e12

Backported to: 4.3.13

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Looks like it's not the difference in slashes but the lower-case "c:" versus upper-case "C:" that's causing UrlResource.equals to not match here... Let's see what we can do about it.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

We're upper-casing drive letter prefixes in addClassPathManifestEntries for proper duplicate detection now. Please give the upcoming 5.0.2.BUILD-SNAPSHOT a try; I'll backport it to 4.3.13 if it works for you.

@spring-projects-issues
Copy link
Collaborator Author

Udayakumar commented

Hello,
Thanks for the prompt fix. i am stuck with downloading the artifactory. I tried by defining spring repo into the settings.xml however i got the following error,

Non-resolvable import POM: Could not transfer artifact org.springframework:spring-framework-bom:pom:5.0.2.BUILD-SNAPSHOT from/to repository.spring.snapshot (http://repo.spring.io/snapshot): connect timed out

Can you help.

@spring-projects-issues
Copy link
Collaborator Author

Udayakumar commented

Found a strange thing. This issue do not exist in 4.2.5.RELEASE

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Oct 26, 2017

Juergen Hoeller commented

The above looks like a temporary problem with the snapshot repository. Trying at a later point might work...

As for this not occurring with 4.2.5, this is expect since Spring's evaluation of the "java.class.path" manifest entry only came in 4.3: #18260

@spring-projects-issues
Copy link
Collaborator Author

Udayakumar commented

I was able to download the artifact and install into local maven repo. I am finding it hard to test because we are using spring boot and versions are getting messed up. I am not able to use the downloaded artifact standalone.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Stéphane Nicoll, overriding the Spring Framework version underneath Boot to a snapshot should work under normal circumstances? Any advice?

@spring-projects-issues
Copy link
Collaborator Author

Udayakumar commented

spring-framework-bom-5.0.2.BUILD-SNAPSHOT is missing

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I've noticed that the last build hasn't properly completed, so would have received an outdated snapshot in any case. Maybe that's also the reason why the last published snapshot appears inconsistent. In any case, I've triggered a new build which should be ready and published in about half an hour.

@spring-projects-issues
Copy link
Collaborator Author

Udayakumar commented

Hi Hoeller,
Thanks for the support. Finally i was able to test with the snapshot. It seem to be working. Hope it works for all scenarios.
Kindly let me know if it will be available in 4.3.12.RELEASE version. Please make it available as part of spring boot versions as well.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good to hear, thanks for the feedback!

I'll backport this to 4.3.13 tomorrow, along with a few other refinements. Both 5.0.2 and 4.3.13 are scheduled for release on November 15th, with corresponding Boot 2.0 RC1 and Boot 1.5.9 releases following soon thereafter.

@spring-projects-issues spring-projects-issues added type: bug A general bug status: backported An issue that has been backported to maintenance branches in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.0.2 milestone Jan 11, 2019
@sbrannen sbrannen changed the title PathMatchingResourcePatternResolver returns duplicate resources when using classpath* prefix [SPR-16117] PathMatchingResourcePatternResolver returns duplicate resources when using classpath*: prefix [SPR-16117] Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants