[Bug 64074] New: getResource() for directories started to return nulls instead of list of files that directory contains

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug 64074] New: getResource() for directories started to return nulls instead of list of files that directory contains

Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=64074

            Bug ID: 64074
           Summary: getResource() for directories started to return nulls
                    instead of list of files that directory contains
           Product: Tomcat 9
           Version: 9.0.30
          Hardware: PC
                OS: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: Catalina
          Assignee: [hidden email]
          Reporter: [hidden email]
  Target Milestone: -----

Created attachment 36963
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=36963&action=edit
a test case that reproduces a bug

In tomcat 9.0.27 when you invoke
getClass().getResource(<directory>).getInputStream() you would get an input
stream containing all files from the directory. In tomcat 9.0.30 that logic has
changed and you get a null instead of an input stream.

We created a small test project to reproduce this error (added to this ticket
as an attachment). When you deploy it to the tomcat 9.0.27 (under namespace
test_tomcat9_war) and access http://localhost:8080/test_tomcat9_war/DemoServlet
you will get

"Full: blah.txt blah2.txt test" message

while when you deploy the same artifact to the tomcat 9.0.30 you will get

"Full was null"
We did some investigation on our side about what has changed and it looks like


When you, in a DemoServlet, invoke getClass().getResource("/full/") you get an
URL object back in both cases.
in tomcat 9.0.30:
you will get an URL object with a handler of class
org.apache.catalina.webresources.CachedResource$CachedResourceURLStreamHandler
then when you call openConnection on that URL object it will delegate the
openConnection to the mentioned handler. That will return
org.apache.catalina.webresources.CachedResource$CachedResourceURLConnection
object. Then when you call getInputStream on it it will return you a null
because it doesn't handle properly a case when the resource is a directory.
This is a simplified description as there are more layers of delegation here -
eventually the org/apache/catalina/webresources/FileResource.java
doGetInputStream() method is invoked and it fails when it tries to return
FileInputStream(resource) - because the resource is a directory.

in tomcat 9.0.27
you will get an URL object with a handler of class
sun.net.www.protocol.file.Handler then when you call openConnection on that RUL
object it will delegate the openConnection to the mentioned handler again. That
will return class sun.net.www.protocol.file.FileURLConnection object. Then when
you call getInputStream() method on it it will return you an input stream that
has a list of files in that directory (the FileURL connection object has a
special logic to handle directories.


Parts of our system rely on this functionality and because of this bug we can't
update to the newest version of tomcat which may be an issue especially when
there is some security fix to be applied.

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 64074] getResource() for directories started to return nulls instead of list of files that directory contains

Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=64074

--- Comment #1 from Remy Maucherat <[hidden email]> ---
This is some custom behavior that worked by accident, getInputStream applies to
files, not directories.
This will probably be WONTFIX.

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 64074] getResource() for directories started to return nulls instead of list of files that directory contains

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=64074

--- Comment #2 from Mark Thomas <[hidden email]> ---
I'll see how easy it is to restore the directory listing behaviour.

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 64074] getResource() for directories started to return nulls instead of list of files that directory contains

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=64074

Mark Thomas <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #3 from Mark Thomas <[hidden email]> ---
It wasn't too bad. And as a nice side-effect it takes account of resourceJARS
and packedWARs when caching is enabled.

Fixed in:
- master for 10.0.0.0-M1 onwards
- 9.0.x for 9.0.31 onwards
- 8.5.x for 8.5.51 onwards

Unless we completely re-implement the JNDI resource handling from 7.0.x (not
something I want to do) there is always going to be some edge case that isn't
supported. At the moment the edge cases that are emerging are simple to
implement. At some point we will reach the point we may reach the point where
we decide the implementation is too complex.

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 64074] getResource() for directories started to return nulls instead of list of files that directory contains

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=64074

--- Comment #4 from Konrad <[hidden email]> ---
Whoa, that was quick, thank you very much!

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]