Details
-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
2.0.21.Final
-
None
Description
In an attempt to fix this Spring Boot issue, I have implemented a custom URLResource subclass that can list resources from a jar. As permitted by the javadoc of Resource, it returns null for both getFile() and getFilePath() as it does not map to a file but to a particular entry within a jar file. Unfortunately, when processing a resource that returns null from getFilePath(), ServletContextImpl.getResourcePaths(String) ignores the resource:
for (Resource res : resource.list()) { Path file = res.getFilePath(); if (file != null) { Path base = res.getResourceManagerRootPath(); if (base == null) { resources.add(file.toString()); //not much else we can do here } else { String filePath = file.toAbsolutePath().toString().substring(base.toAbsolutePath().toString().length()); filePath = filePath.replace('\\', '/'); //for windows systems if (Files.isDirectory(file)) { filePath = filePath + "/"; } resources.add(filePath); } } }
I considered a workaround when I return a dummy Path along with a null resource manager root path so that the path's toString() is used, but I'm concerned that there may be unexpected side-effects of doing do if getFilePath() is called on the Resource elsewhere.
Attachments
Issue Links
- relates to
-
UNDERTOW-1235 ServletContext#getResourcePaths returns erroneous additional paths for exploded war libs
- Resolved