-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Fix null stream issue for resource loading based on relative names #816
base: 9.0.x
Are you sure you want to change the base?
Conversation
|
Sorry, I meant absolute and relative paths, not URLs. I have updated the description body to reflect this. An example case would be the calling the ![]() In line 40, Apache CXF Core calls Tomcat's In line 42, Tomcat's In both calls, the variables within Tomcat's
Regardless of whether the ![]() Since the caching logic within Tomcat's |
These are names not paths. I'm not convinced that 'relative' and 'absolute' are concepts that apply here. Putting that to one side, where is the target resource located so that the 'absolute' lookup fails but the 'relative' one works? Also, relative to what? What would be the 'absolute' path be that did work? |
As per the Java documentation for resource names, "relative" and "absolute" do appear to be terminology that can be used in relation to a resource name, though not in the conventional sense. However, let me re-phrase how I refer to them in my comments:
The resource is found within the cxf-core-3.5.9.jar as The cxf jar is located outside the webapp in an external repository previously added via the addURL method in line 2536:
When the cxf jar is present in an external repository, the 'absolute' lookup using the resource name that starts with a
My use of 'absolute' and 'relative' here have not been used in the conventional sense, but rather are used to indicate the presence of the leading slash similar to how it has been referred in the Java documentation for resource names. However, if we were to use it in the conventional sense, I suppose it would be relative to the external repository?
If this cxf jar is present in the webapp's WEB-INF/lib folder, the lookup with the 'absolute' name starting with
|
Adding to my comment above, when the This PR proposes updating the flow from checking only the |
The Java documentation for resource names also states:
That doesn't mean the issue isn't going to be fixed in Tomcat. But it does mean it looks like CXF has a bug that should be fixed. |
And given that |
I think I understand everything that is going on now. The root cause is that Tomcat accepts name for My plan to deal with this is:
Apps that use incorrect resource names may see a small performance degradation if they try loading the same resource multiple times using the wrong format for a resource name. The fix for that would be for the app to use the correct format. |
Thank you for pointing this out. I will make a report of this via CXF's Jira board.
We are using a custom class loader that extends Tomcat's WebappClassLoader, which makes our custom class loader a subclass of Tomcat's WebappClassLoaderBase.
Thank you, a fix would be much appreciated. |
Please find the issue on CXF's Jira board here: https://issues.apache.org/jira/browse/CXF-9108 I have credited you by linking your GitHub profile and the quoted comment in the report. However, if you have an account in the Jira issue board that you would prefer being tagged instead, please do let me know and I can update the issue. |
I have updated the PR according to this approach. Could you please check? |
This addresses a bug in the
getResourceAsStream
[1] method which falsely identifies resources to be absent when looking them up with relative paths if they have already been looked up with the absolute path.In the getResourceAsStream [1] method, Tomcat checks the recently introduced
notFoundClassResources
based on the "path" variable alone, which is always the absolute path.However, there are cases such as [2] in the Apache CXF core component where the class loading first tries calling the
getResourceAsStream
[1] method with the absolute path as the “name” and if this returns a null stream, it then tries the relative path by calling thegetResourceAsStream
[1] method with the relative path as the “name”.In both calls to the
getResourceAsStream
method, the “path” variable set at [3] is the absolute path and therefore, Tomcat checks the cache for the absolute path both times.As a result, the second attempt based on the relative path gets skipped, and a null stream is returned even though the resource is present.
In this PR, the block where the resource is loaded based on the "name" variable has been moved to a separate if block where the cache is checked for the "name" variable instead of the "path" variable.
[1]
tomcat/java/org/apache/catalina/loader/WebappClassLoaderBase.java
Line 1070 in 0820667
[2] https://github.com/apache/cxf/blob/cxf-3.5.9/core/src/main/java/org/apache/cxf/version/Version.java#L38
[3]
tomcat/java/org/apache/catalina/loader/WebappClassLoaderBase.java
Line 1100 in 0820667