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

Tomcat returns null stream for resource even when present #22632

Open
AmshikaH opened this issue Jan 30, 2025 · 1 comment
Open

Tomcat returns null stream for resource even when present #22632

AmshikaH opened this issue Jan 30, 2025 · 1 comment
Assignees

Comments

@AmshikaH
Copy link
Contributor

AmshikaH commented Jan 30, 2025

Description

Tomcat 9.0.97 has recently introduced a cache to keep track of resources which have been attempted to be loaded once but were not found. This aims to prevent attempting to load resources repeatedly when it has already been identified to be absent.

Prior to loading a resource, Tomcat checks this cache to see if it has been identified to be absent already. If yes, a null stream is returned without re-attempting to load the resource.

Tomcat checks the cache based on the "path" variable alone, which is always the absolute resource name.

However, there are cases such as [1] in the Apache CXF core component where the class loading first tries calling the getResourceAsStream [2] method with the absolute resource name as the “name” and if this returns a null stream, it then tries the relative resource name by calling the getResourceAsStream [2] method with the relative resource name as the “name”.

In both calls to the getResourceAsStream[2], the “path” variable within [3] is the absolute resource name and therefore, Tomcat checks the cache for the absolute resource name both times.

As a result, the second attempt based on the relative resource name gets skipped, and a null stream is returned even though the resource is present.

As a temporary measure, this cache can be disabled, and this will be reverted once the issue is fixed in Tomcat.

A similar issue where external resources were not being loaded was identified and fixed in Tomcat 9.0.98, however, this issue is still present in Tomcat version 9.0.98.

[1] https://github.com/apache/cxf/blob/cxf-3.5.9/core/src/main/java/org/apache/cxf/version/Version.java#L38
[2] https://github.com/apache/tomcat/blob/08206671035f05e205806140b11c10c6eb3ca5c3/java/org/apache/catalina/loader/WebappClassLoaderBase.java#L1070
[3] https://github.com/apache/tomcat/blob/08206671035f05e205806140b11c10c6eb3ca5c3/java/org/apache/catalina/loader/WebappClassLoaderBase.java#L1100

Steps to Reproduce

Upgrade Tomcat to the 9.0.98 (the latest 9.0.x version at this time).

Version

6.0.0

Environment Details (with versions)

No response

@AmshikaH AmshikaH self-assigned this Jan 30, 2025
@AmshikaH
Copy link
Contributor Author

A PR has been sent to Apache Tomcat to address this issue: apache/tomcat#816

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

2 participants