Skip to content

ClassPathResource.createRelative is using wrong ClassPathResource constructor for the returned resource [SPR-16146] #20694

@spring-projects-issues

Description

@spring-projects-issues

Constantino Cronemberger opened SPR-16146 and commented

new ClassPathResource("/test.html") removes the leading slash, but when the method createRelative is called it does not remove the leading slash in the returned resource as in this example:

System.out.println(((ClassPathResource)new ClassPathResource("").createRelative("/test.html")).getPath());

The fix is very simple.

There are two sets of constructors: the ones for when clazz is not specified and the ones for when it is specified.

The createRelative method should choose the right one to use based on the current value of the clazz attribute.


Affects: 4.3.12, 5.0.1

Issue Links:

Referenced from: commits 573ff2c, d00e4f1

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