-
Bug
-
Resolution: Done
-
Major
-
None
-
None
If a PathResource represents a drive root such as C:/ the getName() method throws a null pointer exception.
public String getName() { return file.getFileName().toString(); }
Javadocs for Path.getFileName() state the method will return "null if this path has zero elements"
https://docs.oracle.com/javase/7/docs/api/java/nio/file/Path.html#getFileName()
Therefore, Undertow should not assume that it will get a non-null value back from getFileName().
I noticed this issue when using the CachedResourceManager which creates a CachedResource object whose name matches that of the PathResource.
java.lang.NullPointerException at io.undertow.server.handlers.resource.PathResource.getName(PathResource.java:81) at io.undertow.server.handlers.resource.CachedResource.<init>(CachedResource.java:66) at io.undertow.server.handlers.resource.CachingResourceManager.getResource(CachingResourceManager.java:122) at io.undertow.server.handlers.resource.CachingResourceManager.getResource(CachingResourceManager.java:32) at io.undertow.servlet.handlers.ServletPathMatches.getServletHandlerByPath(ServletPathMatches.java:141) at io.undertow.servlet.handlers.ServletInitialHandler.handleRequest(ServletInitialHandler.java:147)
Therefore, I would recommend instead of returning null for the PathResource name, we return the full Path.toString() representation for a meaningful name.
public String getName() { if( file.getFileName() != null ) { return file.getFileName().toString(); } return file.toString(); }
Pull incoming from my cohort, cerberus23 .
- is incorporated by
-
WFCORE-5801 Upgrade Undertow to 2.2.16.Final
- Closed