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

Introduce getAbsolutePath() in ClassPathResource #29094

Closed
sbrannen opened this issue Sep 6, 2022 · 1 comment
Closed

Introduce getAbsolutePath() in ClassPathResource #29094

sbrannen opened this issue Sep 6, 2022 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: superseded An issue that has been superseded by another theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement

Comments

@sbrannen
Copy link
Member

sbrannen commented Sep 6, 2022

The Javadoc for the getPath() method in ClassPathResource states the following.

Return the path for this resource (as resource path within the class path).

However, that is not always true since that implies the returned path is an absolute path within the class path.

If the ClassPathResource was created using the ClassPathResource(String, Class) constructor with a relative path, the returned path is actually a cleaned version of the relative path supplied to the constructor.

In light of that, we should update the Javadoc for getPath() to reflect the actual semantics and introduce a new getAbsolutePath() method for retrieving the absolute path.

The latter is required by the newly introduced ResourceHints.registerResourceIfNecessary(Resource) method (see #29083).

@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement theme: aot An issue related to Ahead-of-time processing labels Sep 6, 2022
@sbrannen sbrannen added this to the 6.0.0-M6 milestone Sep 6, 2022
@sbrannen sbrannen self-assigned this Sep 6, 2022
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Sep 6, 2022
This commit also improves the overall Javadoc in ClassPathResource.

See spring-projectsgh-29094
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Sep 6, 2022
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Sep 6, 2022
@sbrannen sbrannen removed this from the 6.0.0-M6 milestone Sep 12, 2022
@sbrannen sbrannen added the status: superseded An issue that has been superseded by another label Sep 12, 2022
@sbrannen
Copy link
Member Author

sbrannen added a commit to sbrannen/spring-framework that referenced this issue Sep 12, 2022
Prior to this commit, the Javadoc for the getPath() method in
ClassPathResource stated the following.

> Return the path for this resource (as resource path within the class path).

That implied the returned path was an "absolute path" within the class
path; however, that was not always true.

If the resource was created using ClassPathResource(String) or
ClassPathResource(String, ClassLoader), the returned path was a cleaned
version of the ABSOLUTE PATH supplied to the constructor, WITHOUT a
leading slash.

If the resource was created using ClassPathResource(String, Class) with
an absolute path, the returned path was a cleaned version of the
ABSOLUTE PATH supplied to the constructor, WITH a leading slash.

If the resource was created using ClassPathResource(String, Class) with
a relative path, the returned path was a cleaned version of the
RELATIVE PATH supplied to the constructor.

In addition, ClassPathResource does not provide public access the Class
passed to the ClassPathResource(String, Class) constructor.

Consequently, the path returned by getPath() could not be reliably used
with ClassLoader.getResource(String) or with the recently introduced
registerResource(Resource) method in ResourceHints.

This commit addresses this issue by ensuring that getPath()
consistently returns the absolute path within the class path without a
leading slash.

See spring-projectsgh-29083
Reverts spring-projectsgh-29094
Closes spring-projectsgh-29099
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: superseded An issue that has been superseded by another theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant