Skip to content

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

@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions